dfh123
11-19-2003, 09:03 PM
Here is a snippet of a function to validate a numeric field in my code:
function Number_Validate(theField, len) {
var n = theField.value;
var numpattern = /\D+/
if (n=="") return(true);
if (n.match(numpattern)) {
alert ("This field must be numeric.");
theField.focus();
theField.value="";
return(false);
}
...
}
Then in my html form, I have a series of text boxes, such as this:
<INPUT type="text" onChange="Number_Validate(this,3)"
...
The validation works; that is, when I enter bad data and then hit a tab key or click the mouse to move out of the field, the alert box pops up. However, when I close the alert box, the focus is set to the *next* field, not the one that had the error. Setting the value to null on the error field works, so I know the code is executing. I get no error messages.
Why am I unable to get the focus set on the field I want?
Thanks in advance.
-don
function Number_Validate(theField, len) {
var n = theField.value;
var numpattern = /\D+/
if (n=="") return(true);
if (n.match(numpattern)) {
alert ("This field must be numeric.");
theField.focus();
theField.value="";
return(false);
}
...
}
Then in my html form, I have a series of text boxes, such as this:
<INPUT type="text" onChange="Number_Validate(this,3)"
...
The validation works; that is, when I enter bad data and then hit a tab key or click the mouse to move out of the field, the alert box pops up. However, when I close the alert box, the focus is set to the *next* field, not the one that had the error. Setting the value to null on the error field works, so I know the code is executing. I get no error messages.
Why am I unable to get the focus set on the field I want?
Thanks in advance.
-don