Tags:

How to disabled the enter key in javascript in a web form

Tuesday, May 10, 2011 EDT

by: Eric Potvin

Tags: javascript

For those who likes to disable the "enter" key when submitting a form, well ... this script is not for you. But for all others who wants to know, simply add the following code to your page.

<script type="text/javascript">
function disableEnterKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}
document.onkeypress = disableEnterKey;
</script>

Be the first to reply!

No comments!
Share this article:

Add a comment

* If your comment require a response from us, please make sure you leave your email

Captcha

* is required
The posting of advertisements, profanity, or personal attacks is prohibited.
Please review our terms of use

Latest Articles

Top Articles

Category List

Top of the page
Loading, please wait ...