Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Firefox issues

Status
Not open for further replies.

kss444

Programmer
Sep 19, 2006
306
US
I have the following JavaScript function that uses regexp to not allow typing of letters or special chars into a text box, the problem is that the users will also hve to use ctrl+C, ctrl+v the backspace key the F keys ect. these keys work fine in IE but in Firefox they do not work.

Can anyone help me out,
Thanks,

JS code:
function check_float(e, field) {
//alert(e.keyCode);

var key;
var code;

if (window.event) {
key = String.fromCharCode(e.keyCode);
code = e.keyCode;
}
else if (e.which) {
key = String.fromCharCode(e.which);
code = e.which;

}

if (key.match(/[~!@\+=\''#\""$%\{\}\[\]\\^&*()a-zA-Z]/i)) {
alert("Only digits, dashes and decimal points are allowed!");
return false;
} else {
//alert('key match');
}
}

Ordinary Programmer
 
I'm guessing (because you have not given the relevant code) that you're checking 'onkeypress', 'onkeyup', or 'onkeydown' rather than when focus is lost or the form is submitted.

This is bad because you will get an alert for every wrong key you press - how very, very, very, very annoying.

Why not simply check the field value once on blur/submit, and avoid the need to detect the values of each key pressed? I know I'd be much happier as a user of your site, and it'd keep your code a lot simpler.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Yes you are right, I was using key press, but I found an easier solution to use.
saveNMFCItemNumber.Attributes.Add("onblur", "this.value= this.value.replace(/[~!@\+=\''#\""$%\{\}\[\]\\^&*()a-zA-Z]/gi,'')")

Thanks though

Ordinary Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top