Below there is my code that shows a suggested list of words (rpc.php) when the user type 3 and more letters in the textbox. My question is how can I edit it, that when the user select a suggested word, the form is submitted?
Now when I click on a suggested word it places it in the text开发者_StackOverflow中文版box.
I thought of two possible ways.
- The form is auto submitted when the user selects a suggested word.
The suggested word is a link that gets you correctly to the results page. (I can set the desired link through the rpc.php).
<script type="text/javascript"> $().ready(function() { $("#s").autocomplete("rpc.php", { width: 250, selectFirst: false, minChars: 3, scroll:true, matchContains: true, scrollHeight: 250 }); }); </script>
this is my form
<form method="get" action=".php">
<input type="text" name="s" id="s" class="inputsearch">
<input id="searchform" type="submit">
</form>
$("#s").autocomplete("rpc.php", {
width: 250,
selectFirst: false,
minChars: 3,
scroll:true,
matchContains: true,
scrollHeight: 250
}).result(function(event, item) {
$.ajax({
type: "POST",
url: "some.php",
data: {s:$("#s").val()},
success: function(msg){
alert( "Data Saved: " + msg );
}
});
});
精彩评论