onChange event and focus()

S

SimonFx

Am I right in assuming that you can NOT set focus() back to a field in
its onChange event? Is there another way - I have validation that I
would like to set the focus back to the invalid field onChange?

Eg:
<input type=text" name="tstfld" onChange="window.alert('Changed!');
this.focus()">
 
S

SimonFx

SimonFx said:
Am I right in assuming that you can NOT set focus() back to a field in
its onChange event? Is there another way - I have validation that I
would like to set the focus back to the invalid field onChange?

Eg:
<input type=text" name="tstfld" onChange="window.alert('Changed!');
this.focus()">

I think I have solved this using setTimeout, but it feels dirty.

function validateField (f){
// blah blah field is bad so:
setTimeout ('document.' + f.form.name + '.' + f.name + '.focus()',100);
setTimeout ('window.alert (\'Invalid entry.\')', 100);
}

</SCRIPT>
</HEAD>
<BODY>

<FORM NAME="myForm">
<input type="text" name="myFld" onChange="validateField(this);">
</FORM>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top