Prevent Enter from submitting the form
Updated: 22 May 2010 | 1 comment
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
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").
Would you like to reply?
Login or Register to post your comment.