This one should be pretty easy for you oh so smart javascript gurus ;) I've got a script in ASP that generates the code I have posted below from an XML file. Everything works great except for the fact that I have no way to expand / contract all of the tree. If someone can give me a working solution they get a lot of points. Simple.
If you want to see original source and download the images that this script uses then go here:
http://www.aspfaqs.com/webtech/code/xmltreemenu2.zipAnd here is a link to the coder's demo site:
http://www.aspfaqs.com/demos/xmltreedemo2/<html>
<head>
<title>PESAP v2.0 : Level Map</title>
<link rel=stylesheet href="themes/Standard/defa
ult.css" type="text/css">
<STYLE TYPE="text/css">
<!--
.node { color: black;
font-family : "Helvetica", "Arial", "MS Sans Serif", sans-serif;
font-size : 9pt;}
.node A:link { color: black; text-decoration: none; }
.node A:visited { color: black; text-decoration: none; }
.node A:active { color: black; text-decoration: none; }
.node A:hover { color: black; background : #CCCCCC; text-decoration: none; }
-->
</STYLE>
</head>
<script language=javascript>
function remote2(url){
window.opener.location=url
window.close()
}
</script>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width="31"><img class="LEVEL1" src="../images/minusonly.g
if" id="1" width="31" height="16" border="0"></td>
<td nowrap class="node"> Root (ID: 248)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom" class="LEVEL2" id="2" style="display:">
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img class="LEVEL3" src="../images/folderclose
d.gif" id="3" width="31" height="16" border="0"></td>
<td nowrap class="node"> SHELF (ID: 256)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom" class="LEVEL4" id="4" style="display:none">
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td>
<td width="31"><img class="LEVEL5" src="../images/folderclose
d.gif" id="5" width="31" height="16" border="0"></td>
<td nowrap class="node"> TOOLS (ID: 258)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom" class="LEVEL6" id="6" style="display:none">
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td>
<td width="31"><img src="../images/docjoin.gif
" width="31" height="16" border="0"></td>
<td nowrap class="node"> SAW (ID: 261)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td>
<td width="31"><img src="../images/docjoin.gif
" width="31" height="16" border="0"></td>
<td nowrap class="node"> HAMMER (ID: 262)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td>
<td width="31"><img src="../images/doc.gif" width="31" height="16" border="0"></td>
<td nowrap class="node"> TAPE MEASURE (ID: 265)</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td>
<td width="31"><img class="LEVEL7" src="../images/folderclose
d.gif" id="7" width="31" height="16" border="0"></td>
<td nowrap class="node"> MATERIA
LS (ID: 259)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom" class="LEVEL8" id="8" style="display:none">
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img src="../images/docjoin.gif
" width="31" height="16" border="0"></td>
<td nowrap class="node"> NAILS (ID: 263)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img src="../images/doc.gif" width="31" height="16" border="0"></td>
<td nowrap class="node"> LUMBER (ID: 264)</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img class="LEVEL9" src="../images/folderclose
d.gif" id="9" width="31" height="16" border="0"></td>
<td nowrap class="node"> DESK (ID: 267)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom" class="LEVEL10" id="10" style="display:none">
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img class="LEVEL11" src="../images/folderclose
d.gif" id="11" width="31" height="16" border="0"></td>
<td nowrap class="node"> BUILDIN
G MATERIALS (ID: 268)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom" class="LEVEL12" id="12" style="display:none">
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td>
<td width="31"><img src="../images/docjoin.gif
" width="31" height="16" border="0"></td>
<td nowrap class="node"> LUMBER (ID: 271)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width="18"><img src="../images/line.gif" width="18" height="16"></td>
<td width="31"><img src="../images/doc.gif" width="31" height="16" border="0"></td>
<td nowrap class="node"> HARDWAR
E (ID: 273)</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img class="LEVEL13" src="../images/folderclose
d.gif" id="13" width="31" height="16" border="0"></td>
<td nowrap class="node"> EQUIPME
NT (ID: 269)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom" class="LEVEL14" id="14" style="display:none">
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img src="../images/docjoin.gif
" width="31" height="16" border="0"></td>
<td nowrap class="node"> COMPUTE
R (ID: 270)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img src="../images/docjoin.gif
" width="31" height="16" border="0"></td>
<td nowrap class="node"> MONITOR
(ID: 272)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img src="../images/docjoin.gif
" width="31" height="16" border="0"></td>
<td nowrap class="node"> TELEPHO
NE (ID: 274)</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td><td width='20'><img src="../images/pixel.gif" width='20' height="1" border="0"></td>
<td width="31"><img src="../images/doc.gif" width="31" height="16" border="0"></td>
<td nowrap class="node"> CHAIR (ID: 275)</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<SCRIPT LANGUAGE="Javascript">
<!--
//These two arrays work with each other to identify the menu element that should
//be hidden or made visible. There is a one-to-one relationship between
//the rows of each array. For example arClickedElementID(0) contains the
//ID to access the element ID stored in arAffectedMenuItemID(0).
//Note: The value of the ASP variable iTotal used below represents the
//total number of items and subitems in the menu. The value is set by
//reference in the DisplayNode() subroutine call
var arClickedElementID = new Array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15");
var arAffectedMenuItemID = new Array( "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16");
//This function queries the arClickedElementID[] and arAffectedMenuItemID[] arrays
//to get an object reference to the appropriate menu element to show or hide.
function fnLookupElementRef(sID)
{
var i;
for (i=0;i<arClickedElementID.
length;i++
)
if (arClickedElementID[i] == sID)
return document.all(arAffectedMen
uItemID[i]
);
return null;
}
//This function is responsible for showing/hiding the menu items. It
//also switches the images accordingly
function doChangeTree()
{
var targetID, srcElement, targetElement;
srcElement = window.event.srcElement;
//Only work with elements that have LEVEL in the classname
if(srcElement.className.su
bstr(0,5) == "LEVEL")
{
//Using the ID of the item that was clicked, we look up
//and retrieve an object reference to the menu item that
//should be shown or hidden
targetElement = fnLookupElementRef(srcElem
ent.id)
if (targetElement != null)
{
//First find out if the current folder is empty
//We find out based on the name of the image used
var sImageSource = srcElement.src;
if (sImageSource.indexOf("emp
ty") == -1)
{
if (targetElement.style.displ
ay == "none")
{
//Our menu item is currently hidden, so display it
targetElement.style.displa
y = "";
if (srcElement.className == "LEVEL1")
//Set a special open-folder graphic for the root folder
srcElement.src = "../images/minusonly.gif";
else
//Otherwise, just show the open folder icon
srcElement.src = "../images/folderopen.gif"
;
}
else
{
//Our menu item is currently visible, so hide it
targetElement.style.displa
y = "none";
if (srcElement.className == "LEVEL1")
//Set a special closed-folder graphic for the root folder
srcElement.src = "../images/plusonly.gif";
else
//Otherwise, just show the closed folder icon
srcElement.src = "../images/folderclosed.gi
f";
}
}
}
}
}
//Capture user clicks on the web page and
//call the doChangeTree() function to
//handle the event
document.onclick = doChangeTree;
-->
</SCRIPT>
</body>
</html>
Start Free Trial