I thought this would be really simple, but i'm stumped. I'd like to validate some data without submitting the form, but i can't seem to get the focus to go back to the field with the bad data. I've stripped out most of the code just to illustrate the problem. In both IE and Mozilla, the focus still goes to the next element. This is .php generated.
<html><body><sc ript type="text/javascript">
var numAdults=5;
var numChildren=0;
function Check(element){
value=parseInt( element.value);
if(isNaN(value) || value<0 || value>99){
if(element.name =='txtNumAdults '){
element.value=n umAdults;
}else{
element.value=n umChildren;
}
element.focus() ;
return false;
}else{
//SetDirty(elemen t);
return true;
}
}
</script>
<form action="a1.php" method="POST" name="myFrm">
<table>
<tr><td align="right">< label>Adults:</label></td>
<td><input type="text" name="txtNumAdu lts" size="3" value="5" onChange="Check (this);" /></td></tr>
<tr><td align="right">< label>Children: </label></td>
<td><input type="text" name="txtNumChi ldren" size="3" value="0" onChange="Check (this);" /></td></tr>
</table></form></body></html>
<html><body><sc ript type="text/javascript">
var numAdults=5;
var numChildren=0;
function Check(element){
value=parseInt( element.value);
if(isNaN(value) || value<0 || value>99){
if(element.name =='txtNumAdults '){
element.value=n umAdults;
}else{
element.value=n umChildren;
}
element.focus() ;
return false;
}else{
//SetDirty(elemen t);
return true;
}
}
</script>
<form action="a1.php" method="POST" name="myFrm">
<table>
<tr><td align="right">< label>Adults:</label></td>
<td><input type="text" name="txtNumAdu lts" size="3" value="5" onChange="Check (this);" /></td></tr>
<tr><td align="right">< label>Children: </label></td>
<td><input type="text" name="txtNumChi ldren" size="3" value="0" onChange="Check (this);" /></td></tr>
</table></form></body></html>
Comment