Created
July 1, 2015 15:25
-
-
Save namklabs/e1a89c3f80e2e7f9c644 to your computer and use it in GitHub Desktop.
Prevent form submission by Enter key (jQuery)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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