File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Hiding a popup span with onblur Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Hiding a popup span with onblur" Watch "Hiding a popup span with onblur" New topic
Author

Hiding a popup span with onblur

Chris Huber
Greenhorn

Joined: Mar 26, 2009
Posts: 15
I have a popup that is similar to a 'google suggest' where it creates a drop-down based on the text after each onkeyup... There will be multiple fields like this on a page.

I'm struggling with hiding the popup if the user clicks outside the input box or tabs to the next field. I really want to use onblur, which seems to be designed exactly for this - except when I use it, it hides the popup when you click on a selection in the popup box - prior to it executing the script to put the value in the input box. If it could execute the clicked on action, then hide the box, it would work perfectly.

I'm trying to avoid using the 'find the mouse cursor click and determine if it is inside or outside the popup...' method. With that method I also have to take into account if they tab outside the input box.

Any suggestions?

Here is the slimmed down code:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Not a "Java in General" question. Moving to the HTML/JavaScript forum.
Chris Huber
Greenhorn

Joined: Mar 26, 2009
Posts: 15
I solved it by nesting the popup within the span.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The solution most people would do is add logic to your hide function that sees what element the event fired in and see if it is the child of the wrapper. Also your code is not keyboard accessible so you are limiting your audience to having to use a mouse.

Eric
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hiding a popup span with onblur
 
Similar Threads
scroll bar down
Change value in form onClick
Displaying an inline error message in a JSP
jQuery not working on page
how to use autocomplete in jsf