Forum Moderators: open

Message Too Old, No Replies

onblur and onfocus question

How to tell if an element is focussed when the preceding element is blurred

         

premasagar

1:47 pm on Nov 15, 2004 (gmt 0)

10+ Year Member



Does anyone have a suggestion for this...?

In a form, I have a text input field and I have a select box. When the input field is in focus, the select box is shown. No problems there. Now, when the user clicks out of the input field (i.e. onblur) I want the selectbox to be hidden, unless the user is actually clicking on the selectbox.

That is, at the onblur event of the input field, the selectbox should be hidden, unless the new focus is on the selectbox.

How can I do this? The problem is that the onblur event of the input field is activated before the onfocus event of the selectbox. So, when the onblur event fires, the selectbox isn't actually in focus.

The only way around this that I can think of is to have an onfocus event for every element on the page that is NOT the selectbox and then hide the selectbox when any of those onfocus events fire. But that's a hassle! Can anyone think of a tidier solution?

Thanks,
Prem.

kaled

5:17 pm on Nov 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've never used it but setTimeout should solve the problem.

Arrange for onblur to trigger code to hide the select box after a delay of, say 250 ms. By this time, the select box will be focused so that you can cancel hiding it, if necessary.

Kaled.

premasagar

5:46 pm on Nov 15, 2004 (gmt 0)

10+ Year Member



I've never used it but setTimeout should solve the problem.

Ah, good idea... I'l try that.

code_geek

4:01 am on Nov 18, 2004 (gmt 0)

10+ Year Member



sorry, post is irrevelant after re-reading first post, please disregard this