/    Sign up×
Community /Pin to ProfileBookmark

Div related Tree Menu problem

The problem I have is relatively simple and as far as my understanding goes can be solved in two ways. I have created a tree menu on one side of my page (just to clarify a tree menu which looks like that found in windows when you right click on start and select explore). The menu toggles and is aligned to the left nicely working just as I had intended. The problem occurs when I try and crate two buttons one to cascade collapse all of the open folders of the tree menu and the other to cascade expand all of the folders (I am using tables for my layout not frames).

Every time I tried this I got an error message (just saying there is an error with the JavaScript on page); here is the JavaScript ‘expand’ code I am using.

[CODE]function Expand() {
divs=document.getElementsByTagName(“DIV”);
for (i=0;i<divs.length;i++) {
divs[i].style.display=”block”;
key=document.getElementById(“x” + divs[i].id);
key.innerHTML=”<img src=’Buttons/minus.gif’ width=’9′ height=’9′ hspace=’0′ vspace=’0′ border=’0′>”;
}
}[/CODE]

This is the code that calls the JavaScript for the expand and collapse functions:

[CODE]<a href=”javascript:Expand();”>Expand</a><a href=”javascript:Collapse();”>Collapse</a>[/CODE]

I realize that what is going wrong here (as far as I can tell) is the expand code is making every div on the page expand which includes the divs for align left and has an error when it meets an align div. I end up having code that works with the ‘expand’ function but with wonky alignment (this is once I delete every align left that involves a div). Here is an example of some of the HTML code in the page. This is the strategy file which when clicked drops down the Investment Strategies item.

[CODE]<div align=”left”>
<table border=”0″ cellpadding=’1′ cellspacing=”1″ class=”MenuTree”>
<tr>
<td width=’16’><a id=”xstrategy” href=”javascript:Toggle(‘strategy’);”><img src=’Buttons/plus.gif’ width=’9′ height=’9′ hspace=’0′ vspace=’0′ border=’0’/></a></td>
<td class=”MenuTree”><a id=”xstrategy” href=”javascript:Toggle(‘strategy’);”><img src=’Buttons/strategy.jpg’ border=’0′ /> </a></td>
</tr>
</table>
</div> <div id=”strategy” style=”display: none; margin-left: 1em;”>
<div align=”left”>
<table border=”0″ cellpadding=’1′ cellspacing=”1″>
<tr>
<td width=’16’><img src=’Buttons/text.gif’ width=’16’ height=’16’ hspace=’0′ vspace=’0′ border=’0′ /></td>
<td><a href=”” target=”master”><span class=”MenuTree”><span class=”style31″>Investment Strategies</span></span></a></td>
</tr>[/CODE]

I was wondering if it were possible in the ‘expand’ code to instead of having it expand all divs only expand the specific divs used in the menu tree. I have tried several times but I can’t seem to get the code right. Alternatively is there a way I can align the menus manually. I have tried <p align=’left’> but that gives a double break at the bottom which is no good. I have also applied CSS (MenuTree) to the menu (left align) with no real luck.

Thanks in advance.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJul 04.2005 — I was wondering if it were possible in the ‘expand’ code to instead of having it expand all divs only expand the specific divs used in the menu tree.[/QUOTE]
Instead of this:

divs=document.getElementsByTagName("DIV");

Collect only the DIVs that are in your menu container -- whatever the name of that container may be:

divs=document.getElementById("menuDiv").getElementsByTagName("DIV");
Copy linkTweet thisAlerts:
@Cam_KukiauthorJul 11.2005 — I have tried to implement this line of code and have had much more success than before. Unfortunatly I am still having trouble with how the menu tree expands and contracts. I have included three pics to help explain what happens. The initial state is obviously what the menu looks like before it is interacted with. Once the expand button is clicked the menu expands.

Unfortunatly the plus/minus toggle doesn't work so the add sign is displayed instead of the minus sign.

When contract is selected the whole menu contracts into the BUY folder.

Any help to get this functioning properly would be highly appreciated and thanks phpnovice for your advice so far.

Also here is the code I am using. The javascript:


[CODE]function Toggle(item) {
obj=document.getElementById(item);
visible=(obj.style.display!="none")
key=document.getElementById("x" + item);
if (visible) {
obj.style.display="none";
key.innerHTML="<img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0'>";
} else {
obj.style.display="block";
key.innerHTML="<img src='Buttons/minus.gif' width='9' height='9' hspace='0' vspace='0' border='0'>";
}
}

function Expand() {
divs=document.getElementById("menuContainer").getElementsByTagName("DIV");
for (i=0;i<divs.length;i++) {
divs[i].style.display="block";
key=document.getElementById("x" + divs[i].id);
//key.innerHTML="<img src='Buttons/minus.gif' width='9' height='9' hspace='0' vspace='0' border='0'>";
}
}

function Collapse() {
divs=document.getElementById("menuContainer").getElementsByTagName("DIV");
for (i=0;i<divs.length;i++) {
divs[i].style.display="none";
key=document.getElementById("x" + divs[i].id);
//key.innerHTML="<img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0'>";
}

}[/CODE]


[CODE]The specific HTML code:

<div id="menuContainer">
<a href="javascript:Expand();"><img src="Buttons/RedButtonDown.jpg" border='0'></a></a><a href="javascript:Collapse();" ><img src="/Buttons/GreenButtonUp.jpg" border='0'></a></a>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><a id="xBUY" href="javascript:Toggle('BUY');"><img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0' /></a></td>
<td class="MenuTree"><a id="xBUY" href="javascript:Toggle('BUY');"><img src='Buttons/BUY.jpg' border='0' /> </a></td>
</tr>
</table>
<div id="BUY" style="display: none; margin-left: 1em;">
<div align="left">
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href="Invest/Executive Summary" target="master"><span class="MenuTree">Urgent Buys</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href="Invest/Critical Success Factors" target="master"><span class="MenuTree">Priority Buys</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href="Invest/Investment Planner" target="master"><span class="MenuTree">Routine Buys</span></a></td>
</tr>
</table>
</div>
</div>

<div align="left">
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><a id="xSELL" href="javascript:Toggle('SELL');"><img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0' /></a></td>
<td align="left" class="MenuTree"><a id="xSELL" href="javascript:Toggle('SELL');"><img src='Buttons/SELL.jpg' border='0' /> </a></td>
</tr>
</table>
</div> <div id="SELL" style="display: none; margin-left: 1em;">
<div align="left">
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Urgent Sells</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Priority Sells</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Routine Sells</span></a></td>
</tr>
</table>


</div>
</div>

<div align="left">
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><a id="xCOTS" href="javascript:Toggle('COTS');"><img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0' /></a></td>
<td class="MenuTree"><a id="xCOTS" href="javascript:Toggle('COTS');"><img src='Buttons/COTS.jpg' border='0' /> </a></td>
</tr>
</table>
</div> <div id="COTS" style="display: none; margin-left: 1em;">
<div align="left">
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">COTS Concept</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">COTS Rules</span></a></td>
</tr>
</table>
</div>
</div>


<div align="left">
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><a id="xaccessories" href="javascript:Toggle('accessories');"><img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0' /></a></td>
<td class="MenuTree"><a id="xaccessories" href="javascript:Toggle('accessories');"><img src='Buttons/accessories.jpg' border='0' /> </a></td>
</tr>
</table>
</div> <div id="accessories" style="display: none; margin-left: 1em;">
<div align="left">
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Action Quotes</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Useful Links</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Useful Contacts</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Newsletters</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">References</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Course Notes</span></a></td>
</tr>
</table>
<table border="0" cellpadding='1' cellspacing="1">
<tr>
<td width='16'><img src='Buttons/text.gif' width='16' height='16' hspace='0' vspace='0' border='0' /></td>
<td><a href=""><span class="MenuTree">Glossary</span></a></td>
</tr>
</table>
</div>
</div>
</div>[/CODE]


Thanks in advance

[upl-file uuid=92faf442-4a81-4b51-b135-1d413de1caa7 size=4kB]contract.jpg[/upl-file]

[upl-file uuid=52fde2f8-638e-4f3a-a6cb-c3ab5df365f8 size=8kB]initialstate.jpg[/upl-file]

[upl-file uuid=63ab3f37-6f90-4e9c-9475-fef26cd826d9 size=65kB]menuexp.jpg[/upl-file]
Copy linkTweet thisAlerts:
@phpnoviceJul 11.2005 — A live link to the page in action would be more helpful.
Copy linkTweet thisAlerts:
@Cam_KukiauthorJul 14.2005 — Unfortunatly the site isnt live at the moment and probabley won't be for some time. Sorry if thats too much trouble but thanks for your help anyway ?
Copy linkTweet thisAlerts:
@phpnoviceJul 14.2005 — Next problem... You have this:

<td width='16'><a [COLOR=Red]id="xBUY"[/COLOR] href="javascript:Toggle('BUY');"><img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0' /></a></td>

<td class="MenuTree"><a [COLOR=Red]id="xBUY"[/COLOR] href="javascript:Toggle('BUY');"><img src='Buttons/BUY.jpg' border='0' /> </a></td>

HTML [b]id[/b] attribute values are supposed to be unique within the document. I doubt you really wish to reference the second one by id, so remove that id specification.
Copy linkTweet thisAlerts:
@Cam_KukiauthorJul 17.2005 — I changed the id on each to yBUY ySELL ect. I did not notice any change in the problem but I understand that it is not a good idea to have multiple ids in one doc. One thing that i forgot to mention earlier is that the bottom line of code in the collapse and expand functions is commented.

[CODE]// key.innerHTML="<img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0'>";[/CODE]

When the comments are removed and it is run the menu functions perfectly for BUY (in that it toggles, expands and collapses correctly) but not for the other folders. Thanks for your help.
Copy linkTweet thisAlerts:
@phpnoviceJul 17.2005 — Are you saying that you changed this:

<td width='16'><a id="xBUY" href="javascript:Toggle('BUY');"><img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0' /></a></td>

<td class="MenuTree"><a id="[COLOR=Red]xBUY[/COLOR]" href="javascript:Toggle('BUY');"><img src='Buttons/BUY.jpg' border='0' /> </a></td>

to this?

<td width='16'><a id="xBUY" href="javascript:Toggle('BUY');"><img src='Buttons/plus.gif' width='9' height='9' hspace='0' vspace='0' border='0' /></a></td>

<td class="MenuTree"><a id="[COLOR=Red]yBUY[/COLOR]" href="javascript:Toggle('BUY');"><img src='Buttons/BUY.jpg' border='0' /> </a></td>

A live link sure would help expedite this.
Copy linkTweet thisAlerts:
@Cam_KukiauthorJul 19.2005 — Yes thats right. I'll have a look into setting up a live link this week I should be able to sort something out.
×

Success!

Help @Cam_Kuki spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...