View Full Version : dynamic folder tree menu not folding

08-16-2004, 01:25 AM
Hello all.....

I got a Switch Menu script from Dynamic Drive (http://www.dynamicdrive.com/dynamicindex1/switchmenu.htm) - a folding tree nav menu. Didn't have to do much configuring of the html - just changed a span to a div, but I think that's messing up in the javascript.

This is the html for a menu entry and a sub menu:
<.div id="masterdiv">

<div class="menutitle" onclick="SwitchMenu('sub1')"><a href="index.php?page=ministries/adults">Adults</a></div>
<div class="submenu" id="sub1">
<a href="index.php?page=ministries/adults">Adult Fellowships</a><br>
<a href="index.php?page=ministries/adults">Adult Electives</a><br>
<a href="index.php?page=ministries/adults">Home Bible studies</a><br>
<a href="index.php?page=ministries/adults">What about Sunday School?</a>

I changed the submenu span class to a div class because the span class was only indenting the first line of the submenu.

This is the javascript:
<script type="javascript">
if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')

function SwitchMenu(obj){
var el = document.getElementById(obj);
var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
if(el.style.display != "block"){ //DynamicDrive.com change
for (var i=0; i<ar.length; i++){
if (ar[i].className=="submenu") //DynamicDrive.com change
ar[i].style.display = "none";
el.style.display = "block";
el.style.display = "none";


The problem is that the page opens with the menu opened up and it's not collapsing when the top level link is clicked. Here it is in action:
It's the list in the right side column - the submenus are indented 15px.

What might the matter be? Thanks for any attention!


08-16-2004, 01:42 AM
I suppose I should have put this in the Dynamic Drive scripts help forum. How do I go about moving it? So sorry!!