Problem with form not submitting when Enter is pressed has its background in implementation of event bubbling and/or event capturing. In Internet Explorer events bubbles, on the other hand in other browsers events are being captured and bubbled. Yay!
You can read further on that matter in article on event order at quirksmode.org, which is great site and you should certainly spend some time over there if you already haven’t.
Let’s get down to the essence of this article, which is handling problem of form not submitting when Enter is pressed while some text input field has focus and solution you could find in jQuery.
You have and form:
<form id="signup" action="/process/login-form" method="post"> <label for="answer1">What are you think about blue?</label> <input id="answer1" name="answer1" type="text" /> <input type="submit" value="Answer" /> </form>
and it is bugged down (I have no idea if this phrase exists) as explained above, you are using jQuery (please, don’t use jQuery just to overcome this obstacle – it is non sense) and you are thinking about your solutions.
One of the solutions could be:
$("#answer1").keydown(function(event){
if(event.keyCode == 13 && jQuery.support.submitBubbles) {
$(this).parents("form").submit();
};
})
What that code does is it binds keypress event to the input field of interest and checks on keypress (when that field has focus) if event code corresponds to the keyCode (13) of the Enter key and if it does it sends submit to the parent form, which could be called by its id, but this way you can address different input fields with same class from different forms, which is not rare on web today, to have a whole bunch of forms in one page.
jQuery.support object is “A collection of properties that represent the presence of different browser features or bugs.” as it is said in jQuery reference. It relies on feature detection (not browser detection) which is recommended and safer method.
I hope you find this article helpful.