Try the following version of your script.
The focus() method in the onChange event doesn't do anything because during the event the focus has not changed. Your user changes the focus later, after the event has completed.
But with the setTimeout method, you are delaying the snippet of code long enough that the onChange event completes, then the onFocus event fires.
Because the timed-out code fires in its own context, you have to use an independent reference to the text box (getElementById...).
I like to use the parameter value (pT) where possible. When referencing an element, I like to use the ID attribute, not the NAME attribute, because NAME is not unique. When I use both on an element, I always make sure they are the same (ID=NAME). Yours are not (CivilStatus != ccCivilStatus).
function myChange(pT)
{
switch(pT.value.toUpperCase())
{
case 'M':
case 'R':
document.getElementById('SpouseFN').disabled=false ;
document.getElementById('SpouseMN').disabled=false ;
document.getElementById('SpouseLN').disabled=false ;
document.getElementById('SpouseNS').disabled=false ;
break;
case 'S':
document.getElementById('SpouseFN').disabled=true;
document.getElementById('SpouseMN').disabled=true;
document.getElementById('SpouseLN').disabled=true;
document.getElementById('SpouseNS').disabled=true;
break;
default:
alert('Your input '+ pT.value + ' is incorrect!');
setTimeout('document.getElementById(\''+pT.id+'\') .focus()',10);
break;
}
}
-Van
(Old dog learning new tricks...)
|