Link to home
Start Free TrialLog in
Avatar of lcftahoe
lcftahoe

asked on

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>       
ASKER CERTIFIED SOLUTION
Avatar of shivsa
shivsa
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial


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
Avatar of Asta Cu
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.
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