473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Javascript Keys routine doesn't work in FireFox

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

Feb 7 '06 #1
2 3007
Sorted it.

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

Rgds Robbie
"Astra" <No@Spam.com> wrote in message
news:11************@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


Feb 7 '06 #2
Astra wrote:
Sorted it.

Found a great tutorial in Google - sorry for the hassle!!
URL?
[...]
"Astra" <No@Spam.com> wrote in message
news:11************@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.
If you want to restrict input to certain characters, forget using keycodes
and look at the actual text that has been entered. Use a regular
expression to check it fits your requirements.

Methods based on keycodes are easily defeated and very unreliable.


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;
Browser sniffing is soooo last millennium.

var shiftcheck = (navigator.appName == "Netscape") ? e.SHIFT_MASK :
event.shiftKey;
And again...
[...]

This routine basically forces the user to only enter numbers from either the
main keyboard set or the numeric keypad.
No, it doesn't. If JS is disabled the user can press any key they like
with impunity. Or use copy/paste. Or use script entered via the address
bar to set the value, or...

Like I said before it works fine
in IE, but the key codes for Firefox seem to be different.
That is another reason why keycodes are very unreliable.


Any ideas as to what the solution is?


Use a regular expression or other method to check the characters entered,
not the keys pressed.
--
Rob
Feb 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Cliff R. | last post by:
Hi, I use a handy little Javascript Flash detection script on a number of sites (copied below). Usually works great, but I just started trying Firefox and it's not working. A few browsers are...
19
by: tnhoe | last post by:
Hi, any excel like grid javascript which is stable and fast to load thousand of rows data ? can it have F2 function to popup another window ? can validate cell value when cursor move away that...
9
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
14
by: xxbmichae1 | last post by:
I have a <select> object that i've set up an onchange event that fires in IE fine when I use the cursor up and down in the list, but If I use the cursor up and down in Firefox the event doesn't...
8
by: Adam | last post by:
Hey, I'm using JS to submit a form with image submit buttons, using the following code... (Page is here... http://www.cards2do.co.uk/addcard.php?card_id=292 ) ...
7
by: C.Joseph Drayton | last post by:
I have a problem that I am hoping someone can help me with. First let me describe the problem. I have an HTML form that in one field has an onBlur call to a JavaScript function. When you exit the...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
8
by: Mateusz Viste | last post by:
Hi, I'm not sure if my question is really related to JavaScript, so please excuse me if that's not the case (and maybe you guys would have an idea what's the cause is and where could I ask)... ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.