Using onKeyDown to check for form submission is bad, mmk?
I’m a big fan of AJAX submission of forms. Recently I’ve gotten lazy and omitted the FORM tag for single (and dual) input interfaces, instead checking for enter-keypress form submission using the onKeyDown event on my form elements.
This lazyness is now biting me in the butt when using Virgin America, Washington Mutual, and many other commercial sites. When the user is entering text into a text input element, many browsers present a pull-down menu of previous inputs for similar fields.
Using latest FireFox on OS X, the enter event on the browser’s drop down menu is propagated to the HTML input element. Although I pressed enter in the context of a browser interface component, the event is propagated to the page element, where it triggers form submission.
Lesson learned: Always use onsubmit on your surrounding form element. Don’t have a form element? You might be unpleasantly surprised that IE6 will create one for you, using all input elements on the page as form elements and the page’s URL as the POST destination. Remove ambiguity, remove fail.
