Forum Moderators: open

Message Too Old, No Replies

.focus() in FireFox

         

Nutter

1:40 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



I'm working on a series of forms and part of my validation code should set focus back to the invalid field. I'm using the .focus() method in the JS script when the data is invalid after an alert() to the user. It works fine in IE, but does not work in FF.

The code that does not work:
document.forms.frmwhatever.txtfield.focus()

But, if I wrap it in a setTimeout it seems to work.
setTimeout("document.forms.frmwhatever.txtfield.focus()", 50);

The setTimeout method appears to work in both browsers, but it seems like the hard way to do things, and I'm always looking for the easy way :-)

Thanks,
- Ryan

Nutter

3:04 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



Turns out, .select() works in both and has the effect I'm after. But, I'm still wondering if there is a work around other that setTimeout()

RonPK

8:50 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> document.forms.frmwhatever.txtfield.focus()

IMHO that should be:

document.frmwhatever.txtfield.focus()

Who knows, maybe Firefox chokes on such a minor syntax error. I'm not even sure whether it is a syntax error.