Disable Enter Key to avoid undesired form submit

1 Dec

This javascript code was used to eliminate the problem that some users like me like to hit Enter Key when dealing with forms to submit, but in the browser sometimes don’t work, for me a solution was to just eliminate it.


<script type = “text/javascript”>
//call the keyDown function
document.onkeydown = keyDownHandler;

//Then you have the method to catch the keydown
function keyDownHandler(e) {

var keyCode = e ? e.keyCode : window.event.keyCode;

if (keyCode == 13 || keyCode == 116){ // blocks enter and F5 on any browser

if (!e) {
window.event.keyCode = 0;
}//if !e

return false;

}//if keyCode = 13



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: