In my form there is a textbox and submit button. When a user starts typing, after the 3rd letter the autocomplete script does it’s magic.
There are two possibilities.
- The user types a word, there are matches and he clicks on one match. This selected match is added to the textbox and then hits the submit button.
- The user types a word, there/there are not matches but he decides to hit the submit button without selecting one of the suggested.
My question is how can I identify whether he hit the button in case 1 or in case 2.
rpc.php is the file that looks for suggested values through the mySQL.
A solution is to check the string if there is on the database but I do not want this.
Another solution is to transform the jQuery script and php code that shows the product name and instead of putting the product in the textbox, it should take him to the results page. This solves my problem also.
<script type="text/javascript">
$().ready(function() {
$("#s").autocomplete("rpc.php", {
width: 250,
selectFirst: false,
minChars: 3,
scroll:true,
matchContains: true,
scrollHeight: 250
});
});
</script>
<form method="get" action=".php">
<input type="text" name="s" id="s" class="inputsearch">
<input type="submit">
</form>
Use autocomplete’s
changemethod to set a flag in the form, egThe “change” event fires when the value in the text field changes. When an AC item is chosen
ui.itemwill contain an object reference to the selected item from the list. If no selection was made, ie the user simply entered text,ui.itemwill be null.Your form handler can then check for
$_GET['ac_flag']to determine whether or not the value came from the autocomplete list.Quick mockup example here – http://jsfiddle.net/9GQgh/