468,244 Members | 1,827 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,244 developers. It's quick & easy.

onChange event and focus()

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()">
Jul 23 '05 #1
1 2850
SimonFx wrote:
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>
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Asit | last post: by
2 posts views Thread by crjunk | last post: by
10 posts views Thread by david.bercot | last post: by
7 posts views Thread by Tim Slattery | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.