I have an input box for which I am using the Jquery autocomplete function. When I type in the input box, the list appears correctly with the 16 first “values”. When I click on one of the values, the input box is populated with that value. So, so far everything ok. My problem is as follows. The list is not filtered according to my input. The list stays static. I do not understand why. Hope someone can help. Thank you in advance for your replies. Cheers. Marc.
My HTML:
<input type="text" id="moi"/>
My PHP:
<?php
header('Content-Type: text/html; charset=utf-8');
require("../inc/connect.inc.php");
mysql_set_charset('utf8');
$result = mysql_query("SELECT * FROM search_loc_test");
$row=mysql_fetch_assoc($result);
$return = array();
while($row=mysql_fetch_assoc($result)){
array_push($return,array('label'=>$row['seaerch_loc'],'value'=>$row['seaerch_loc']));}
echo(json_encode($return));
?>
My JS:
$( "#moi" ).autocomplete({
source: "php/search_loc.php",
minLength: 2
});
You need to update your SQL query to process the
termsent by the autocomplete.When your source is called (via GET) it will be called as follows :
php/search_loc.php?term=bbSo in your PHP script you need to take the search term and use it to filter the results from the DB … Something like :
Docs for LIKE here