Basically I got a PHP file that returns an array of different results (the PHP Sends the array and is received fine). Now I want that the JQuery autocomplete only search by the field “Name” and not by the other ones and that it only display the field “Name” when is suggesting results. but once is selected I want it to put in the page all the array of results.
Currently it is displaying everything that is pulling all array in the suggested search and only putting in the HTML the ‘name’.
I think what i have to do is catch the variables that are in JQ and then search just the name
Can anyone help me plz? thx u
PHP (WORKS)
foreach ($this->get_charities() as $r){
$return = array ( 'Name' => $r['Name'],
'Contact' => $r['Contact'],
'Postcode' => $r['Postcode'],
'Phone' => $r['Phone'],
'Fax' => $r['Fax'],
'Website' => $r['Website'],
'Email' => $r['Email'],
);
}
return json_encode($return);
JS
<script>
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#birds" ).autocomplete({
source: "search.php",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
});
</script>
You need to set array in php as below
Now, auto complete only search on Name values and also you can get your custom values into select function