Forum Moderators: open
This function checks to see that a certain text box, created dynamically, has a number as the value.
If it doesn't, we want to set the focus to that field, and it doesn't work.
we have tried to create the field name through javascript code as well using "thefield" as a variable.
We don't get an error message, neither do we get the focus. (see line 8)
Any ideas? THANKS.
alert(thefield.name);
to see if it's actually finding the object?
I would add an id to these objects and approach it this way, all you'd need to do is generate an ID as you generate the name:
document.write('<input type="text" name="'+somename+'" id="'+somename+'">');
With the exception of radio buttons, the id can be the same as the name.
function chb(v){
document.uform.check[v].checked = true;
var scode = document.uform.check[v].value;
var fld = "distpaid" + scode;
var thefield = document.getElementById(fld);
if (isNaN(theField.value) ¦¦ theField.value == ""){
alert("Please enter only numbers");
thefield.focus();
}
}
When the alert box closes, focus will be returned to the active control, however, the multi-threaded nature of browsers and operating systems means that there may be a race condition between you explicitly setting the focus and the focus being set by the closure of the alert box.
Kaled.