Users are mistakenly pressing the enter/return key when filling in webform which causes form to submit.
Looking for snippet to disable enter/return key so that form does not submit until user clicks on "submit" button.

Thanks

Comments

quicksketch’s picture

Title: Disable enter/return while submitting webform » Disable enter/return while submitting webformdff

Use this bit of jQuery. Done correctly, you should theme the form and add the javascript to the page through theming (follow the instructions in THEMING.txt and just add the javascript to the new template file).

For a quick hack you can make the Description Full HTML and put in the code directly.

<script type="text/javascript">
$('input').keypress(function (event){ return event.keyCode == 13 ? false : true; });
</script>

The jquery.js file must already be added to the page for this to function properly.

quicksketch’s picture

Title: Disable enter/return while submitting webformdff » Disable enter/return while submitting webform

Oops, changed the title.

Also, because this isn't a Webform request, I'd suggest learning jQuery from one of these fine sources:
http://visualjquery.com
http://docs.jquery.com/How_jQuery_Works

quicksketch’s picture

Status: Active » Closed (fixed)
AimAdvantage’s picture

Instead of installing or depending on an external .js file- this solution was much lighter and easier for me-

I found this one to work fairly easily by creating a full html block and entering these few lines of code:

<script type="text/javascript"> 

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

</script>

Hope this is a simpler solution.

Aaron
http://www.aimadvantage.com/