• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

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

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
lcftahoe
Asked:
lcftahoe
  • 2
  • 2
1 Solution
 
shivsaCommented:


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
 
Asta CuCommented:
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
 
Asta CuCommented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now