Forum Moderators: open

Message Too Old, No Replies

Focus dectecting

I need to know if the user has focused on a text place

         

adni18

2:12 pm on Apr 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to know if an input field is focused.

Rambo Tribble

2:21 pm on Apr 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The onfocus HTML event handler will fire when the element is focused on. Just include it in the tag for the element and have it call the desired JavaScript action.

adni18

10:12 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No! I mean that i need to know if the field is focused on at a given time, not as soon as it is focused on. This might help. I am trying to figure out if the document.selection.createRange() is inside of a textbox.

Rambo Tribble

11:10 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not aware of a standard way to directly test the focus of an element, but you could set a flag for the element with the onfocus event and unset it on the onblur event. Testing the flag's state would reveal the element's focus status.

IE 6 has a method, hasFocus(), that checks for a document having focus, but I don't believe it's granular enough to do what you want. It returns a Boolean true if the document or any of its elements has focus. You do realize createRange() is IE-only?