mattdaddy.net info that bounces inside my brain that makes sense to me, maybe you.

9Jan/096

TECH: Hitting enter?

Okay, so how many of you hit Enter to move between fields in a form online? I didn't realize that hitting enter will submit a form because I've never done that. I either click in the boxes, or use tab.

Anyway, I built a form and the requestor wanted to disable enter on the whole thing.  Why?  I don't know, but I wanted her to stop bugging me :)

I found a way to do it, but it's kind of a pain.  The first part is the javascript function, make sure it's between the head tags.

<script language="JavaScript">
function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}
</script>

The last part is something you have to put in every single text box (and I had about 100 - thank goodness for find and replace)

<input type=”text” name=”mytext” onKeyPress=”return disableEnterKey(event)”>

The important part is the part in red. Just slap that in each input tag, and you're ready to go.

Anyone have an easier way of doing it?