Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts

    close drop down menu

    I've got an auto-suggestion menu. A drop down menu appears when the user begins to type into a search form. I want the menu to disappear when the user clicks anywhere outside of the menu.

    Code:
    function disappear()
    {
    	var menu = document.getElementById("suggestions");
    	menu.style.display = 'none';
    }
    I've got something like that set up so far. I just don't know how to use it for when the user clicks on the page.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    You need to include the whole of the page outside the menu into a <div>, then something like:-

    Code:
    <script type = "text/javascript">
    function disappear(){
    var menu = document.getElementById("suggestions");
    menu.style.display = 'none';
    }
    </script>
    
    <div id = "div1" onclick = "disappear()">
    text here <br>
    more text here<br>
    still more stuff here<br>
    </div>

    It is your responsibility to die() if necessary….. - PHP Manual


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •