FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

Disable "Enter" Key in Form script




Description:
Is the user pressing the "Enter" key in the middle of your form causing inadvertent and incomplete form submissions? This script disable the "Enter" key when pressed inside chosen fields of your choice (most commonly <input type="text"> fields). Moreover, it then advances the cursor to the next field within the form. Very useful.
Code:

<script type="text/javascript">

function handleEnter (field, event) {
      var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
      if (keyCode == 13) {
         var i;
         for (i = 0; i < field.form.elements.length; i++)
            if (field == field.form.elements[i])
               break;
         i = (i + 1) % field.form.elements.length;
         field.form.elements[i].focus();
         return false;
      }
      else
      return true;
   }     

</script>

Smile



0 blog comments below




FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.