Video Screencast Help
Search Video Help Close Back
to help
New in the Rewards Catalog: Vouchers for "Symantec Technical Specialist" and "Symantec Certified Specialist" exams.

Prevent Enter from submitting the form

Updated: 22 May 2010 | 1 comment
DrGonzo65's picture
0 0 Votes
Login to vote

I have a long web form and a few users have pressed Enter by accident before they complete it, submitting an incomplete form.  Is there a way to keep the Submit button from responding to a press of the Enter key?

Thanks

discussion Filed Under:

Comments

claus66's picture
08
Oct
2009
1 Vote +1
Login to vote

A little javascript

Hi

Add the following in the Script-field (Right click form -> Edit form -> Behavior Tab):

function cancelEnter(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 = cancelEnter; 

A little explanation :
The script will cancel all 'Enter's (evt.keyCode == 13)  whilst in a textbox (node.type=="text").