javascript - click opens menu, click again closes

Associate
Joined
26 Jun 2003
Posts
1,140
Location
North West
At the moment, when u click the menu item, it expands, displaying a div. Clicking again, closes it. As expected. But when I click a link inside the opened div, it closes again.

Heres my code (its actually my mates code that im trying to ejust)

Im not actually sure what the maxwell is and why its needed. There must be a better version around.

Basically like the "Posting Rules" at the bottom of these forums.

Code:
<script language="javascript">
<!--
var state = 'none';

function showhide(layer_ref)
{
	if (state == 'inline')
		state = 'none';	
	else
		state = 'inline';

	if (document.all)
		eval( "document.all." + layer_ref + ".style.display = state");

	if (document.layers)
		document.layers[layer_ref].display = state;

	if (document.getElementById && !document.all)
	{
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.display = state;
	}	
}
//-->
</script>

...
<h1><a href="javascript:showhide(\'WebsiteSettings\');">Website Settings</a></h1>
<div id="WebsiteSettings" style="display:none">
<dl>
<dt>Settings</dt>
<dd><a href="?p=sitesettings">Site Settings</a></dd>
</dl>
</div>
...

Thx
 
Last edited:
a click on the link will reload the page therefore the menu will disapear again



JonD said:
At the moment, when u click the menu item, it expands, displaying a div. Clicking again, closes it. As expected. But when I click a link inside the opened div, it closes again.

Heres my code (its actually my mates code that im trying to ejust)

Im not actually sure what the maxwell is and why its needed. There must be a better version around.

Basically like the "Posting Rules" at the bottom of these forums.

Code:
<script language="javascript">
<!--
var state = 'none';

function showhide(layer_ref)
{
	if (state == 'inline')
		state = 'none';	
	else
		state = 'inline';

	if (document.all)
		eval( "document.all." + layer_ref + ".style.display = state");

	if (document.layers)
		document.layers[layer_ref].display = state;

	if (document.getElementById && !document.all)
	{
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.display = state;
	}	
}
//-->
</script>

...
<h1><a href="javascript:showhide(\'WebsiteSettings\');">Website Settings</a></h1>
<div id="WebsiteSettings" style="display:none">
<dl>
<dt>Settings</dt>
<dd><a href="?p=sitesettings">Site Settings</a></dd>
</dl>
</div>
...

Thx
 
well the posting rules obviously open a new window

so you could use something like the following for your link text

<a href="'#" onclick="window.open('pagename?p=sitesettings','')">Site Settings</a>

some further information here

JonD said:
How do I stop that?
 
Not a new window, the little arrow that opens/closes the box. Im lookin at the code but cant get it to work.
 
again doesnt quite link back itself as in the top code

always to a further directory with a different page to load

the answer for your query about how it works is probably with a fair bit of code / work im afraid.
 
Last edited:
yeh im trying to set a cookie now but cant get it to work.

After browsing the source for this forum I can find anywhere where the cookie is being loaded and setting the collapse anywhere. :confused:
 
Back
Top Bottom