Click to See Complete Forum and Search --> : Key code pressed in Netscape


krahb
12-06-2002, 05:54 PM
Hi all,

Inside an html textbox tag I have an "onKeyPress" event that invokes function "myFunction". Inside "myFunction", I use the "event.keyCode" syntax to read the key code pressed by the user from IE browser. What is the syntax to get the key code pressed from Netscape?

Secondly, I also have an "onChange" event in this textbox. Inside "onChange" event handler I have logic to focus back to the textbox in case of illegal data entry:

document.myform.mytextbox.focus();
return false;

IE works perfect but Netscape tabs to the next control regardless. Anyone has any idea why?

Thanks in Advance
krahb

gil davis
12-06-2002, 06:22 PM
keyCode
Unlike IE, Netscape passes the event through the arguements array of the event handler.

function myKey(e) {
if (event)
{ky = event.keyCode;}
else
{ky = e.which;}
return ky;
}

onChange
It may work once the keypress is fixed. Otherwise post a link to your page.