Skip to content

Instantly share code, notes, and snippets.

@jeremysimmons
Created June 9, 2014 18:13
Show Gist options
  • Save jeremysimmons/00ebcf0065d1b7004fdf to your computer and use it in GitHub Desktop.
Save jeremysimmons/00ebcf0065d1b7004fdf to your computer and use it in GitHub Desktop.
prevent enter key
<script type="text/javascript">
//Stop Form Submission of Enter Key Press
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
// if the keyCode was Enter, and node that caused event was not a textarea, submit or button, cancel the event
if (evt.keyCode == 13 && node.type != "textarea" && node.type != 'submit' && node.type != 'button') { return false; }
}
document.onkeypress = stopRKey;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment