Solved

Supress or substitute for Enter key on web form

Posted on 2004-08-20
4
481 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
4 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 400 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now