Skip to content Skip to sidebar Skip to footer

Jquery Autocomplete Submit Form On Select Item, Button Click And/or Enter?

I'm trying to use jQuery Autocomplete to redirect a user to a url based on the input selection. I've seen other questions that address parts of my problem, but I am having trouble

Solution 1:

Added autoFocus: true; to focus on the first item in the results. Then had to get the url from the focused item.

focus: function (event, ui) {
        currentUrl = ui.item.url; 
}


functionbtnGoClick() {
if (currentUrl !== "") go(currentUrl);
}

Added .keypress mapped to 13 (enter key) on the input field for enter key redirect.

$("#states").keypress(function (event) {
if (event.which == 13) {
    event.preventDefault();
    btnGoClick();
}
});

Also set a specified url if no match was found.

http://jsfiddle.net/wfaxvm43/8/

Post a Comment for "Jquery Autocomplete Submit Form On Select Item, Button Click And/or Enter?"