jquery autocomplete update of multiple fields
Hi,
I wonder if anyone can help... I have adapted the jquery autocomplete to update multiple fields on autocompletion of the source field which in this case the id of the input field is Company. As an example the additional input fields have an id of Telephone and Mobile.
When i run the example the auto complete picks up the relevant data from the database table and subsequently populates the Company field wen a value is selected. However the values of Telephone and Mobile do not populate.
I have changed the values in the val(data[1]) and val(data[2]) to read val(data[0]) which does display the Company name in either the telephone or Mobile fields so I know that the code for passing the values over to the relevant fields is correct I just don't have the values for Telephone or Mobile (and yes they are in the database)
main page
- <script type="text/javascript">
$(document).ready(function(){
$("#Company").autocomplete("autocompleteCompany.php", {
matchContains: true,
mustMatch: true,
selectFirst: false
});
$("#Company").result(function(event, data, formatted) {
$("#Telephone").val(data[1]);
$("#Mobile").val(data[2]);
});
});
</script>
Second bit of code retrieves the data for autocompletion and passing values back to main page
- $data = strtolower($_GET['q']);
if (!$data) return;
$sql="SELECT DISTINCT CompanyName FROM $tbl_name WHERE CompanyName LIKE '%$data%' ORDER BY CompanyName";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$CompanyName = $row['CompanyName'];
$Telephone = $row['Telephone'];
$Mobile = $row['Mobile'];
echo "$CompanyName|$Telephone|$Mobile\n";
}