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>       
lcftahoeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 CuTechnical consultant & graphic designCommented:
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 CuTechnical consultant & graphic designCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.