• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

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
2. If I can't do 1, ignore the Enter key

I have tried:

      function checkEnter(e) {
            keyCode = (e.which) ? e.which : e.keyCode;
      document.onkeypress = checkEnter(window.event);

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.
1 Solution
dspaceAuthor Commented:
OK, I'm halfway there.  This suppresses the Enter key...

                  function trapKeypress(e, theKey) {
                        var iKeyCode = 0;
                        if (window.event) iKeyCode = window.event.keyCode
                        else if (e) iKeyCode = e.which;
                        return (iKeyCode != theKey);
            <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">
      <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.
Another way to disable Enter

add to body or head tag

      <script language="JavaScript">
if (document.layers || document.all) document.onkeypress = f1;
function f1(e)
     if ((document.layers && e.which == 13) || (document.all && window.event.keyCode == 13))
          return false;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now