I have a form. When each text field is left (onblurr), I validate the contents and if its not acceptable, I clear the field and set the cursor to the start of that field. Here’s the code:
function checkit(field) {
var pattern=””
var message=””
if (field.value != null) {
if(field.name == “Zipcode”) {
pattern = /[D]/g
message = “Please enter only numbers.”
}
else if(field.name == “Zipcode4”) {
pattern = /[^0-9]/g
message = “Please enter only numbers.”
}
:
:
:
var a = field.value;
if(!pattern.test(a)) return true;
alert(message);
field.value = “” ;
field.focus()
return false ;
}
}
The thing is, it works fine in IE, but not in any Mozilla based browser (Netscape, Firefox, etc.). What happens is that the field in question is blanked, but the cursor goes to the next field.
Can anyone tell me how to get it to work in both kinds of browsers?
Thanks in advance.
Jim
ps. Oddly enough, it also works (sort of) in Safari.