Jump to content

Javascript Menu - Help Needed


Recommended Posts

Hi, http://www.willissinclair.com/090525.phpI need some help with my menu. When you click on 'About' the menu expands and there are six options under it. When you click on one of the options, then menu shrinks back up again. How can I fix it so that the menu stays open when you are on a page that is a 'subcategory'? I don't write my own js, I got it off of a webpage awhile back (I might have gotten it off cssplay - I don't remember). Any help would be greatly appreciated. My menu java script:

window.onload=show;function show(id) {var d = document.getElementById(id);	for (var i = 1; i<=10; i++) {		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}	}if (d) {d.style.display='block';} }

HTML involving menu:

		  	<dl id="menulist">	<dt onclick="java script:show('smenu2');"><a href="#">About</a></dt>			<dd id="smenu2">				<ul>					<li><a href="http://www.willissinclair.com/awards.php">Awards</a></li>					<li><a href="http://www.willissinclair.com/employment.php">Employment</a></li>					<li><a href="http://www.willissinclair.com/faq.php">FAQ</a></li>					<li><a href="http://www.willissinclair.com/news.php">News</a></li>					<li><a href="http://www.willissinclair.com/services.php">Services</a></li>					<li><a href="http://www.willissinclair.com/whitepapers.php">White Papers</a></li>				</ul>			</dd>			<dt onclick="java script:show();"><a href="http://www.willissinclair.com/projects.php">Projects</a></dt>		<dt onclick="java script:show();"><a href="http://www.willissinclair.com/portfolio.php">Portfolio</a></dt>		<dt onclick="java script:show();"><a href="http://www.willissinclair.com/contact.php">Contact</a></dt></dl>

Thanks in advance!Jessy.

Link to comment
Share on other sites

Thank you! Once again, you've helped solve my problems :)I tried using CSS styles to hide my menu while the page was loading. I wasn't successful so I googled how to, but I haven't gotten anything to work. I am able to hide the subcategories fine, they just won't expand again. Any suggestions? Thanks, Jessy

Link to comment
Share on other sites

Set the display property of any element you want hidden to "none".
Okay, help me out. I don't think I understand.
window.onload=show;function show(id) {var d = document.getElementById(id);for (var i = 1; i<=10; i++) {if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}}if (d) {d.style.display='block';} }

I tried changing the last <d.style.display='block'> to 'none'. This did hide the subcategories during onload, but it also made them remain hidden. I couldn't click on 'About' and get them to expand again. What do I need to change?Thanks very much!

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...