Hello,
I have a search form with an autocomplete function. At the moment, it will fill the form with the value in the autocomplete, but you have to hit search after it is filled. How would I go about filling the form input and submitting the form onClick? Code is below...
The jQuery
Code:
function suggest(inputString){
if(inputString.length == 0) {
$('#suggestions').fadeOut();
} else {
$('#search').addClass('load');
$.post("autosuggest.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').fadeIn();
$('#suggestionsList').html(data);
$('#search').removeClass('load');
}
});
}
}
function fill(thisValue) {
$('#search').val(thisValue);
setTimeout("$('#suggestions').fadeOut();", 300);
}
The onClick event
PHP Code:
echo '<ul id="autolist">'; while ($result = $query ->fetch_object()) { echo '<li onClick="fill(\''.addslashes($result->Last_Name).'\');"><p>'.$result->Last_Name.', '.$result->First_Name.'</p></li>'; } echo '</ul>';
|