Forum Moderators: open

Message Too Old, No Replies

Collapsible Menus

How to remember current state when navigating to a page

         

aspdaddy

12:43 pm on Mar 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am using this collapisble menu script and generating the html below from a CMS to list out all the categories and articles within each category but default them to collapsed so that only the categories show.

After locating an artoicle and clicking on it the menus collapse, but I want the category to stay un-collapsed so that users can view other articles of the same category,. Any ideas how to fix it ?

Thanks

<script>
function toggleMenu(objID) {
if (!document.getElementById) return;
var ob = document.getElementById(objID).style;
ob.display = (ob.display == 'block')?'none': 'block';
}
</script>

<div id="navigation" style="width:215px;">

<div class="nav_header" onclick="toggleMenu('menu1')">
<a href="#" title="Heading 1">Heading 1</a></div>
<div id="menu1" class="nav_item" style="display:none; margin-bottom:10px;">
<span class="nav_text"><a href="http://..." title="Link 1">Link 1</span></a>
<span class="nav_text"><a href="http://..." title="Link 2">Link 2</span></a>
<span class="nav_text"><a href="http://..." title="Link 3">Link 3</span></a>
</div>

<div class="nav_header" onclick="toggleMenu('menu2')">
<a href="#" title="Heading 2">Heading 2</a></div>
<div id="menu2" class="nav_item" style="display:none; margin-bottom:10px;">
<span class="nav_text"><a href="http://..." title="Link 4">Link 1</span></a>
<span class="nav_text"><a href="http://..." title="Link 5">Link 2</span></a>
<span class="nav_text"><a href="http://..." title="Link 6">Link 3</span></a>
</div>

PHP_Chimp

2:23 pm on Mar 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want the browser to remember something then you could use a cookie, or you are going to have to use something like a url fragment to control the state.
I would suggest that a cookie would be your best bet. It would also allow a person to return to the same menu state the next time they visit your site.