By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

onChange event and focus()

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.