logo

Disable enter key in a form

Date: 2009-02-26

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.


Code:

<script language="JavaScript">
function disableEnterKey(e)
{
var key;

if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox

if(key == 13)
return false;
else
return true;
}
</script>


2. Than in the form issue onKeyPress like this:

Code:

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


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

Code:

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



ubuntudog.com © 2017 | About | Sitemap | Contact