Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-24-2008, 05:56 PM   PM User | #1
Bob42
Regular Coder

 
Join Date: Jul 2007
Posts: 100
Thanks: 1
Thanked 0 Times in 0 Posts
Bob42 is an unknown quantity at this point
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.
Bob42 is offline   Reply With Quote
Old 08-24-2008, 06:21 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:15 AM.


Advertisement
Log in to turn off these ads.