Disable enter key in a form

There are two simple ways to disable enter key in your forms.

1. The first one is a piece of javascript that you include in your head section.

<script language="JavaScript">
function disableEnterKey(e)
var key;
key = window.event.keyCode; //IE
key = e.which; //firefox

if(key == 13)
return false;
return true;

2. Than in the form issue onKeyPress like this:

<input type="text" onkeypress="return disableEnterKey(event)">

The easiest way of disabling the enter key may be this one:

<input type="text" onkeypress="return event.keyCode!=13" />

Leave a Comment