Solved

Supress or substitute for Enter key on web form

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

12 Experts available now in Live!

Get 1:1 Help Now