Forum Moderators: not2easy

Message Too Old, No Replies

keeping expanded menus expanded after click.

how do I keep menus expanded after click?

         

jcsmolich

4:01 pm on Dec 19, 2006 (gmt 0)

10+ Year Member



Hi,
I'm using a javascript 'show - hide' function in conjunction with css to expand menus onclick. Problem is... I want the menu to remain expanded after the user surfs to a new page. Currently the menu slides back up when you hit another page. Any ideas? Below is sample code that I'm using to expand the menus on click. Can I add additional code to help me keep the menus expanded after hitting another page?
thanks

<script language="JavaScript" type="text/JavaScript">
<!--
menu_status = new Array();
function showHide(theid){
if (document.getElementById) {
var switch_id = document.getElementById(theid);

if(menu_status[theid]!= 'show') {
switch_id.className = 'show';
menu_status[theid] = 'show';
}else{
switch_id.className = 'hide';
menu_status[theid] = 'hide';
}
}
}

//-->
</script>

<a class="home" onclick="showHide('mymenu1')" href="javascript:;">Registration</a>

<div id="mymenu1" class="hide">
<a href="/convention/2007/register/overview.asp" class="submenu"><img src="/images/arrow_green.gif" border="0" /> Overview</a></div>

Fotiman

4:42 pm on Dec 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need some way to transmit that information from page to page. You could:

1. Record it in a cookie or Session variable
2. Record it in a hidden form field that must be included on every page.

The Cookie approach is probably much easier. You'll need to attach a listener to your expand/collapse buttons and the listener will update a cookie with the state of the shown/hidden stuff. And when the page loads, you'll need to look at that cookie to determine which items to show/hide.

Hope that helps.