This question is locked. New answers and comments are not allowed.
I'm trying to catch the enter key press in a ComboBox control so I can prevent the form being submitted and instead focus the next control.
I have this working fine for the standard controls, however I'm having an issue with it on a ComboBox...
The above code will work if the alert is in there... with the combo focused, it shows the key codes as the keys are pressed, and if enter is pressed, it will work as expected (and not submit the form).
If the alert is commented out, the form submits... it's as if some other event is firing before the e.preventDefault() is reached.
I've tried the same code on $("#MyCombo") as well as $("#MyCombo-input"), but it doesn't help.
It's worth noting that this only fails when something is selected in the combo box... if you focus the combo and hit enter without having selected anything, it works as expected.
I have this working fine for the standard controls, however I'm having an issue with it on a ComboBox...
$(function () { $("#MyCombo-input").live('keydown', function (e) { var keyPressed; if ((e.charCode) && (e.keyCode == 0)) keyPressed = e.charCode else keyPressed = e.keyCode; //alert(keyPressed); if (keyPressed == 13) { e.preventDefault(); focusNextControl(); } });});The above code will work if the alert is in there... with the combo focused, it shows the key codes as the keys are pressed, and if enter is pressed, it will work as expected (and not submit the form).
If the alert is commented out, the form submits... it's as if some other event is firing before the e.preventDefault() is reached.
I've tried the same code on $("#MyCombo") as well as $("#MyCombo-input"), but it doesn't help.
It's worth noting that this only fails when something is selected in the combo box... if you focus the combo and hit enter without having selected anything, it works as expected.