Skip to content

Instantly share code, notes, and snippets.

@namklabs
Created July 1, 2015 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namklabs/e1a89c3f80e2e7f9c644 to your computer and use it in GitHub Desktop.
Save namklabs/e1a89c3f80e2e7f9c644 to your computer and use it in GitHub Desktop.
Prevent form submission by Enter key (jQuery)
var code = null;
jQuery(window).keypress(function(e){
code = e.which;
});
jQuery('#myform').submit(function(e){
if( code == 13 ){//if Enter is pressed...
code = null;//Reset keycode to allow submission via click.
e.preventDefault();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment