Solved

Supress or substitute for Enter key on web form

Posted on 2004-08-20
4
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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