The post Enter Key as the Default Button describes how to set the default behaviour for enter key press. However, sometimes, you need to disable form submission on Enter Key press. If you want to prevent it completely, you need to use OnKeyPress handler on <body> tag of your page.
<body OnKeyPress="return disableKeyPress(event)">
key = window.event.keyCode; //IE
key = e.which; //firefox
return (key != 13);
If you want to disable form submission when enter key is pressed in an input field, you must use the function above on the OnKeyPress handler of the input field as follows:
<input type=”text” name=”txtInput” onKeyPress=”return disableEnterKey(event)”>
Want automatic updates?
Subscribe to our RSS feed
Get Email Updates
sent directly to your inbox!