Solved

Javascript code to disable enter key doesn't work in Netscape

Posted on 2003-11-19
5
511 Views
Last Modified: 2008-02-26
The code below does not work in Netscape 7+ (does work in IE). How do I work around this?

   <script language="javascript" type="text/javascript">
          <!--
          document.onKeyDown = function keyPress(evt)
               {
               var keyCode =
               document.layers ? evt.which :
               document.all ? event.keyCode :
               document.getElementById ? evt.keyCode : 0;
               if (keyCode == 13)
                   return false;
             
               }
          //-->
          </script>       
0
Comment
Question by:lcftahoe
  • 2
  • 2
5 Comments
 
LVL 24

Accepted Solution

by:
shivsa earned 500 total points
ID: 9782807
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9782840


To capture keystrokes, it's a little different in IE and Netscape (of course). Here is code which will work in either browser:

document.onkeypress = getKey;
function getKey(keyStroke) {
   var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
   var keyString = String.fromCharCode(keyCode).toLowerCase();
}

Your form's onKeyDown event should then simply call getKey() to enter the function.

http://www.breakingpar.com/bkp/home.nsf/Doc?OpenNavigator&U=CACEB633F995E9CE87256AFB00141646
0
 
LVL 27

Expert Comment

by:Asta Cu
ID: 10376647
No response here, so can only assume that shivsa has helped and the solution is to be accepted.  Will check back shortly and post Moderator recommendation.
0
 
LVL 27

Expert Comment

by:Asta Cu
ID: 10398047
lcftahoe,
No comment has been added lately (2 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to shivsa http:#9782840

Please leave any comments here within 4 days.

-- Please DO NOT accept this comment as an answer ! --


Thanks,
astaec
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft edge browser 7 71
Troubleshoot SharePoint 2013 Excel Services on IE 11 14 125
Parsing an RSS Feed 4 44
Deployment issue on AWS S3 1 34
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

828 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