justlearning
09-11-2002, 07:59 PM
I am writing a program that will be used by different people in with different browsers. However, I am running into a problem when I try to force a field to be numeric.
My code is :
function checkNumber(fld) {
var validNum = "0123456789.";
var numOk = "yes";
var tmp;
for (var i=0; i<fld.value.length; i++) {
temp = "" + fld.value.substring(i, i+1);
if (validNum.indexOf(temp) == "-1") numOk = "no";
}
if (numOk == "no") {
alert("This field is numeric. Only numbers and decimals allowed.");
fld.focus();
fld.select();
}
}
The selection is
<input type="text" name="idnum" onBlur="checkNumber(this);">
This code works fine in IE 5.5, Netscape 4.7 and Konquerer 3.0. However, when using Netscape 6.2, Netscape 7.0, Mozilla 1.0 or Mozilla 1.1, after someone clicks on the ok button from the alert, the next field is selected rather than the field that they entered the wrong information in.
The strangest thing is that I also have a validate function from the submit button that checks the this field for length and uses the document.form_name.idnum.focus(); command if it is too small or too long and that focus works correctly.
I have tried hard coding the exact same command to go back to the idnum field and it does not work in the checkNumber function.
Can anyone tell me why my focus is not working in the later browsers and if there is a command or a way to make it work?
Thanx,
JustLearning
My code is :
function checkNumber(fld) {
var validNum = "0123456789.";
var numOk = "yes";
var tmp;
for (var i=0; i<fld.value.length; i++) {
temp = "" + fld.value.substring(i, i+1);
if (validNum.indexOf(temp) == "-1") numOk = "no";
}
if (numOk == "no") {
alert("This field is numeric. Only numbers and decimals allowed.");
fld.focus();
fld.select();
}
}
The selection is
<input type="text" name="idnum" onBlur="checkNumber(this);">
This code works fine in IE 5.5, Netscape 4.7 and Konquerer 3.0. However, when using Netscape 6.2, Netscape 7.0, Mozilla 1.0 or Mozilla 1.1, after someone clicks on the ok button from the alert, the next field is selected rather than the field that they entered the wrong information in.
The strangest thing is that I also have a validate function from the submit button that checks the this field for length and uses the document.form_name.idnum.focus(); command if it is too small or too long and that focus works correctly.
I have tried hard coding the exact same command to go back to the idnum field and it does not work in the checkNumber function.
Can anyone tell me why my focus is not working in the later browsers and if there is a command or a way to make it work?
Thanx,
JustLearning