Disable Enter Key Within Forms

Description Javascript

If you have an HTML form on your web page, many times your visitors may hit the 'Enter' key on their keyboard, instead of the 'Tab' key, thinking it will advance them to the next form field. However, the 'Enter' key will actually submit the form. This will cause you to receive incomplete form submissions.

To avoid this problem, you can use a piece of JavaScript within your HTML code that will disable the 'Enter' button within your forms until it is completely filled out.

Author: Web Source (Website)

The Code Download

  1. function stopRKey(evt) {
  2.     var evt = (evt) ? evt : ((event) ? event : null);
  3.     var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  4.     if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
  5. }
  6.  
  7. document.onkeypress = stopRKey;

Credits

Added by JC on 15th November 2007

Comments

There are no comments about this snippet.

Post Comment Github Markdown Supported

You must be logged in to post a comment.

Login here to post a comment