using jquery I have a autocomplete text box like the combobox example on the jQuery UI website http://jqueryui.com/demos/autocomplete/#combobox
$("#mycombobox").combobox();
This is basically an input textbox, menu, and button.
the problem is on the aspx page I have mycombobox on there is an asp:button that wires up to submit the form when enter is pressed.
in combobox
$(<input>)
.autocomplete(...)
.keydown(function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 13 || keyCode == 108) {
$(this).blur();
return false;
}
return true;
})
keydown is my hacky way of preventing it to submit, but it only 开发者_C百科gets it half right. I want the first time you press enter for the autocomplete's change event to be called and the second time enter is pressed the form can submit.
without the keydown hack, change is still called on the autocomplete but not until after submit is called, using the old value. I would prefer not to do it that way at all and find a better way.
Edit
if something is selected it has the right behavior, how could I manually select the first option when the menu is shown?you could check to see if the autocomplete UI is visible to handle what pressing enter will do
$('.ui-autocomplete').is(':visible')
精彩评论