Tree Menu Script Problem

This is a discussion on "Tree Menu Script Problem" within the JavaScript Forum section. This forum, and the thread "Tree Menu Script Problem are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 13th, 2005, 15:47
New Member
Join Date: Sep 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Tree Menu Script Problem

Here's my script for opening and closing a folder in a tree menu:

Code: Select all
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]images/folder.gif[/img]";
   } else {
      obj.style.display="block";
      key.innerHTML="[img]images/textfolder.gif[/img]";
   }
}
Here's what I want it to do, I need my tree menu to only open one level at a time, so for example:
If I have 2 folders, folder a & folder b,

folder a
subfolder a-a
subfolder a-b
folder b
subfolder b-a
subfolder b-b

and I click on folder a, I want to be able to click on folder b and have folder a close. I want it to do the same for all the submenus. Thanks for any help!
Reply With Quote

  #2 (permalink)  
Old Sep 14th, 2005, 04:53
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
You need to use a variable to track if a folder is open, and which one it is. Then when you go to open another you'd check that and close it if necessary.
Reply With Quote
  #3 (permalink)  
Old Sep 14th, 2005, 11:39
New Member
Join Date: Sep 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Could you give an example maybe?
Here's some sample code of the tree structure if it helps:

Code: Select all
<table border=0 cellpadding='1' cellspacing=1><tr><td width='16'>[img]images/folder.gif[/img]</td><td>Incidents / Accidents by</table>
	<div id="area1" style="display: none; margin-left: 1em;">
		<table border=0 cellpadding='1' cellspacing=1><tr><td width='16'>[img]images/folder.gif[/img]</td><td>Power Production</table>
			<div id="area1.1" style="display: none; margin-left: 1em;">
				<table border=0 cellpadding='1' cellspacing=1><tr><td width='16'>[img]images/folder.gif[/img]</td><td>Hydro</table>
					<div id="area1.1.1" style="display: none; margin-left: 1em;">
						<table border=0 cellpadding='1' cellspacing=1><tr><td width='16'>[img]images/text.gif[/img]</td><td>Matrix Level</td></tr></table>
						<table border=0 cellpadding='1' cellspacing=1><tr><td width='16'>[img]images/text.gif[/img]</td><td>Number</td></tr></table>
						<table border=0 cellpadding='1' cellspacing=1><tr><td width='16'>[img]images/text.gif[/img]</td><td>Type</td></tr></table>
						<table border=0 cellpadding='1' cellspacing=1><tr><td width='16'>[img]images/text.gif[/img]</td><td>Work Area</td></tr></table>
					</div>
This isn't the cleanest because the code section won't scroll lol
Thanks!
Reply With Quote
  #4 (permalink)  
Old Sep 14th, 2005, 17:12
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
I didn't test this, but I don't think I made any mistakes:

Code: Select all
// new stuff
iopen = "";

function Toggle(item) { 
	if (iopen!="") doToggle(iopen);
	doToggle(item);
}
// end new stuff

// old stuff with some changes
function doToggle(item) { 	// changed function name
   obj=document.getElementById(item); 
   visible=(obj.style.display!="none") 
   key=document.getElementById("x" + item); 
   if (visible) { 
     obj.style.display="none"; 
     key.innerHTML="[img]images/folder.gif[/img]"; 
	 iopen="";	// new line
   } else { 
      obj.style.display="block"; 
      key.innerHTML="[img]images/textfolder.gif[/img]"; 
	  iopen=item;	// new line
   } 
}
Reply With Quote
  #5 (permalink)  
Old Sep 15th, 2005, 00:57
New Member
Join Date: Sep 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, and that works great for the top level only, but I need all the levels, sublevels included to work in the same way, similar to windows explorer so when you click on a folder on each level every other folder closes!
Reply With Quote
Reply

Tags
tree, menu, script, problem

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with tree menu mcnika JavaScript Forum 1 May 22nd, 2008 13:13
CSS JS tree menu & IE6 cheekyGirl JavaScript Forum 6 Feb 26th, 2008 14:30
A tree menu problem jim28100 JavaScript Forum 0 Dec 12th, 2007 09:45
TREE-view disply problem sreenivas2k Classic ASP 0 Jul 19th, 2006 09:37
Problems with javascript tree menu. Please help. Rei03 JavaScript Forum 0 Nov 20th, 2005 01:35


All times are GMT. The time now is 19:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43