Click to See Complete Forum and Search --> : test for focus


jkruer01
03-10-2003, 05:37 PM
How do you test to see if a field has focus? I know that field.focus() will put the focus in that field but how do I find out if a field has focus?

Example:
if( field.focus == true )
{
...
}

I tried this though and it didn't work. Any ideas?

Thanks!

gil davis
03-10-2003, 05:47 PM
There is no property called focus, only a function called focus() and an event called onfocus. You can create your own property and add it to the object.<input type="text" onfocus="this.hasFocus=true" onblur="this.hasFocus=false">Then you can useif (document.formName.fieldName.hasFocus)
{ ... }
else
{ ... }

jkruer01
03-10-2003, 06:02 PM
thanks, it works great.