Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnBlur problem with drop down list

Status
Not open for further replies.

orion2347

IS-IT--Management
Mar 4, 2002
10
SG
Hi everyone!

I've got a parent page that spawns a popup page. In the popup page I have this line of code:

<body onBlur="window.focus();">

Basically I want the popup window to try to remain in focus whenever the user tries to navigate away from it without closing the popup. This works wonderfully for what I want to achieve with the focus issue.

Now the problem lies with drop down lists in the popup window. When I click the drop down list, it just closes immediately after "dropping-down" and I can't select a list item. When I remove the above line of code, the lists work. Could someone please suggest a solution?

Thanks in advance!
 
Mmm... ok, scrap that stuff I said in the above message. Seems the onBlur event also comes into effect (ie. loses focus) if you enter a form tag as well. Does anyone have any suggestions as to how I can keep the popup window persistent and still make use of the form elements in the popup?

Thanks!
 

The select box is losing focus (closing) because another element (the body) is gaining focus (which you do when it loses focus), and only 1 thing can have focus at once.

Suggest you write a JS function called something like "checkFocus"... which you call:

Code:
<body onBlur="checkFocus();">

Then the checkFocus function would see if the see if the currently focused (focussed?) element is a child of the body, and if not, don't do anything. If it isn't (i.e. nothing in your window is focused), then you can go ahead and call window.focus().

Hope this helps,
Dan
 
Thanks for the reply! :D If I created the function as you mentioned, it would mean that I'd probably have to keep track of "flag" variables to see if any of the elements in the form is in focus? Might there be another way to go about tracking the elements?

Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top