开发者

How to auto submit the suggested value from the autocomplete jQuery script?

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.

  1. The form is auto submitted when the user selects a suggested word.
  2. 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 );
                     }
            });
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜