I have made a autocomplete control as given below.
var PrimaryPhy = <?php include('getdata.php'); ?>;
$("#PatientID").autocomplete({
source: PrimaryPhy,
autoFocus:true
});
getdata.php
<?php
$con = mysql_connect("localhost","***","***");
if(!$con){
die("Error : ".mysql_error());
}
mysql_select_db("DBname",$con);
$patient_info = array();
$result = mysql_query("select * from tablename");
while($row = mysql_fetch_array($result)){
$patient_info[] = $row['Name'];
}
echo json_encode($patient_info);
?>
Here I have brought all the Name information of all records from the table. But i wanted to do like Dropdown with option values. For example :
<option value="1">Item 1</option>
Likewise i need to bring the primary key ID of the table as a value for that item. How can i achieve that?
And also If i place one more autocomplete control next to this control, How can i make that first autocomplete's output as a input to the second autocomplete's input?
You can accomplish it by <datalist>
.
The <datalist>
element, a new addition in the HTML5 specification, allows developers to create native autocomplete dropdowns for their web applications.
The <datalist>
element is used to specify all of the possible values for the autocomplete list like below:
<datalist id="languages">
<option value="HTML">
<option value="CSS">
<option value="JavaScript">
</datalist>
For detailed example, you can check here