Link to home
Start Free TrialLog in
Avatar of dspace
dspace

asked on

Supress or substitute for Enter key on web form

I have a web form and would like to globally either:

1. Change the Enter key to a Tab key
or
2. If I can't do 1, ignore the Enter key

I have tried:

<SCRIPT LANGUAGE="JavaScript">
      function checkEnter(e) {
            keyCode = (e.which) ? e.which : e.keyCode;
            if(keyCode==13){
                    return(false);
                  }
            }
      document.onkeypress = checkEnter(window.event);
</SCRIPT>

and that has no effect at all.

I have MANY textboxes on the form so I don't want to have to do an on... for each textbox.  Thanks.
Avatar of dspace
dspace

ASKER

OK, I'm halfway there.  This suppresses the Enter key...

<SCRIPT LANGUAGE="JavaScript">
                  function trapKeypress(e, theKey) {
                        var iKeyCode = 0;
                        if (window.event) iKeyCode = window.event.keyCode
                        else if (e) iKeyCode = e.which;
                        return (iKeyCode != theKey);
                  }
            </SCRIPT>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      </HEAD>
      <body text="#000000" vLink="#2f588f" aLink="#afae6b" link="#2f588f" bgColor="#ffffff"
            leftMargin="0" topMargin="0" onkeypress="return trapKeypress(event, 13);>

Now I only need to find out how to turn it into a Tab key insted of just supressing it.
ASKER CERTIFIED SOLUTION
Avatar of iboutchkine
iboutchkine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial