470,591 Members | 1,586 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Problem with focus

ra
Hi

I can't figure this out - I have a routine that is triggered after a text
field is changed and if an error it displays an alert message and should put
focus back to the field in error but focus or select won't seem to work -
the cursor just stays in the next field.

Im using IE6.0

The code is like

<script>
CheckNumeric(num){
// Some error checking code
if (error)
{num.focus();
num.select();}}
</script>
// some more html...
<input name="t1" type="text" size="5"
onchange='javascript:CheckNumeric(this)'>
/// and so forth...



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #1
1 3963
Yeah I've run in to this also. The problem is that the onBlur event for the
input fires after the onChange method. So while the focus is being set in
the onChange event, the onBlur event is called next and the input loses its
focus.

You may want to try to kill the event chain by setting the event.returnValue
to false or and this is what I do, is give up on the onChange event and
implement the same code in the onBlur event. Yeah you may incur slight
overhead because now you are processing the input field every time you tab
off the control rather than only when the value changes, but if you need to
you can always code this functionality easily in the onBlur handler method
with a simple "if" statement.

Regards
Mike

"ra" <r@yahoo.com> wrote in message news:3f**********@corp.newsgroups.com...
Hi

I can't figure this out - I have a routine that is triggered after a text
field is changed and if an error it displays an alert message and should put focus back to the field in error but focus or select won't seem to work -
the cursor just stays in the next field.

Im using IE6.0

The code is like

<script>
CheckNumeric(num){
// Some error checking code
if (error)
{num.focus();
num.select();}}
</script>
// some more html...
<input name="t1" type="text" size="5"
onchange='javascript:CheckNumeric(this)'>
/// and so forth...



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dave | last post: by
4 posts views Thread by Nitin | last post: by
1 post views Thread by Ricardo Garcia | last post: by
6 posts views Thread by nizar.jouini | last post: by
1 post views Thread by avnrao | last post: by
1 post views Thread by clickon | last post: by
3 posts views Thread by ngkuhlmann | last post: by
3 posts views Thread by jan.loucka | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.