Re: Javascript Keys routine doesn't work in FireFox
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Javascript Keys routine doesn't work in FireFox

From: Astra <No@Spam.com>
Date: Tue Feb 07 2006 - 12:46:53 CET

Sorted it.

Found a great tutorial in Google - sorry for the hassle!!

Rgds Robbie

"Astra" <No@Spam.com> wrote in message
news:11ugv1brbh4df9@corp.supernews.com...
Hi All

I have a JS routine to prohibit users from entering a range of chars in a
textbox and although this works perfectly in IE x, in the latest version of
Firefox it appears to be blocking keys that I want to allow. The routine
sort of still works, but its as if the mapping of the keys is worked out
completely differently. I thought the key maps would be universal.

My code is as follows:

HTML:

<INPUT TYPE="TEXT" NAME="qty" SIZE=5 MAXLENGTH=12 CLASS='FormQtyBox'
VALUE="1" onKeyDown='return CheckQtyEntry(event)' onKeydown='return
CheckQtyEntry(event)'>

JS:

function CheckQtyEntry(e) {
 var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
 var shiftcheck = (navigator.appName == "Netscape") ? e.SHIFT_MASK :
event.shiftKey;

 if (shiftcheck) {
  if (key == 8 || key == 9 || key == 46 || (key > 95 && key < 106)) {
   return true;
  }
  else {
   return false;
  }
 }
 else {
  if (key == 8 || key == 9 || key == 46 || (key > 36 && key < 41) ||
     (key > 47 && key < 58) || (key > 95 && key < 106)) {
   return true;
  }
  else {
   return false;
  }
 }
}

This routine basically forces the user to only enter numbers from either the
main keyboard set or the numeric keypad. Like I said before it works fine
in IE, but the key codes for Firefox seem to be different.

Any ideas as to what the solution is?

Thanks

Robbie
Received on Tue Feb 7 21:39:04 2006