Question

Got a situation here, I am using jquery autocomplete on a textbox. I am also listening to the keypress event on the textbox... so that when I type in the textbox, autocomplete shows up with suggested text, if I do not select the suggested text and press enter, it should submit the form, if I select a suggested text and hit enter, it selects the suggested value and closes the autocomplete box, if I hit enter again, it will submit the form.

Firefox, works like a charm, but not in Chrome, it seems that autocomplete plugin is hijacking the enter key(keycode 13, every other key works), so when I click on enter without choosing a suggested text, nothing happens.

Has anyone had this issue before? And what's the fix?

Thanks in advance.

James

Was it helpful?

Solution

OK, I have come across the post talking about keeping focus on the input field, which gave me some hints on solving this problem.

The trick is to use "keydown" instead of "keypress" to listen to the input event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top