Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Supress or substitute for Enter key on web form

Posted on 2004-08-20
4
Medium Priority
?
497 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:dspace
2 Comments
 

Author Comment

by:dspace
ID: 11851485
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.
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 1600 total points
ID: 11854351
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;
      }
}
</script>
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question