开发者

jQuery autocomplete trigger button on select

I'm using Jorn Zaefferer's Autocomplete query plugin, http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

Everything seems to be working as it should: I type in some text and I get the suggestions. When the suggestions pop up, I have to click on one: that triggers the textbox being filled with the suggestion and hides all the other ones. Then I have to click on the Search开发者_运维问答 button (or use the Enter button instead of clicking).

Is it possible to avoid having to click (or press Enter) twice ? Are there any options that can be set so that selecting a suggestion not only fills the textbox but also triggers the click event on the button ?

I tried using the select option, like so:

    $('#txtSearch').autocomplete({
        source: '/dictionnaire/autocomplete',
        select: function (event, item)
        {
            alert("testing");
        },
        width: 358
    });

... but the alert doesn't show up. Any suggestions ?


I think you should use jquery UI autocomplete instead of that since that plugin is deprecated in favor of the other.

Then i would do something like you did:

$('#txtSearch').autocomplete({
    source: '/dictionnaire/autocomplete',
    select: function (event, item)
    {
        if (event.keyCode == 13){
            $('#idOfYourForm').submit()
        }
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜