Submitting a form on 'Enter' with jQuery?

Posted by b. e. hollenbeck on Stack Overflow See other posts from Stack Overflow or by b. e. hollenbeck
Published on 2009-03-30T21:16:19Z Indexed on 2010/03/13 3:57 UTC
Read the original article Hit count: 322

Filed under:
|
|
|
|

I have a bog-standard login form - an email text field, a password field and a submit button on an AIR project that's using HTML/jQuery. When I hit Enter on the form, the entire form's contents vanish, but the form isn't submitted. Does anyone know if this is a Webkit issue (Adobe AIR uses Webkit for HTML), or if I've bunged things up?

I tried:

$('.input').keypress(function(e){
      if(e.which == 13){
       $('form#login').submit();
       }
      });

But that neither stopped the clearing behavior, or submitted the form. There's no action associated with the form - could that be the issue? Can I put a javascript function in the action?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about forms