G'Day All,
I'm new to the forum, and I'm new to Javascript but I have been using ASP for years. It's about time I took the plunge into Javascripting....
What I'm trying to do is create a vertical menu (standard left column html menu) to where a user clicks on a link/item and it expands a sub-menu below it. Easy to do using the following:
<html>
<head>
<script type="text/javascript">
function getItem(id)
{
var itm = false;
if(document.getElementById)
itm = document.getElementById(id);
else if(document.all)
itm = document.all[id];
else if(document.layers)
itm = document.layers[id];
return itm;
}
function toggleItem(id)
{
itm = getItem(id);
if(!itm)
return false;
if(itm.style.display == 'none')
itm.style.display = '';
else
itm.style.display = 'none';
return false;
}
</script>
</head>
<body>
<a href="#" onclick="toggleItem('table01')">LINK 01</a><br>
<table style="display:none; border-collapse: collapse" id="table01">
<tr>
<td> <a href="#">SUB LINK 01</a></td>
</tr>
<tr>
<td> <a href="#">SUB LINK 02</a></td>
</tr>
<tr>
<td> <a href="#">SUB LINK 03</a></td>
</tr>
</table>
<a href="#" onclick="toggleItem('table02')">LINK 02</a><br>
<table style="display:none; border-collapse: collapse" id="table02">
<tr>
<td> <a href="#">SUB LINK 01</a></td>
</tr>
<tr>
<td> <a href="#">SUB LINK 02</a></td>
</tr>
<tr>
<td> <a href="#">SUB LINK 03</a></td>
</tr>
</table>
</body>
</html>
With this setup, if you click on Link 01 it expands the table just fine. Click on it again and it collapses, exactly what I want it to do.
If you click on Link 01, it expands, but it click on Link 02, Link 01 remains open, and Link 02 Opens as well. I'd like Link 01 to close when Link 02 is clicked, and visa versa (no matter how may links and collapsable tables are on the page).
Lastly, I'd like the current selection to be passed on to the next page when loaded so the menu remains the same until the user changes the menu. I'd also like to do this without using frames if possible.
Any help? Remember, I'm a beginner so comments in the script explaining what is occuring would be greatly appreciated!!!!
Much thanks to anyone who helps!
DethanB
I'm new to the forum, and I'm new to Javascript but I have been using ASP for years. It's about time I took the plunge into Javascripting....
What I'm trying to do is create a vertical menu (standard left column html menu) to where a user clicks on a link/item and it expands a sub-menu below it. Easy to do using the following:
<html>
<head>
<script type="text/javascript">
function getItem(id)
{
var itm = false;
if(document.getElementById)
itm = document.getElementById(id);
else if(document.all)
itm = document.all[id];
else if(document.layers)
itm = document.layers[id];
return itm;
}
function toggleItem(id)
{
itm = getItem(id);
if(!itm)
return false;
if(itm.style.display == 'none')
itm.style.display = '';
else
itm.style.display = 'none';
return false;
}
</script>
</head>
<body>
<a href="#" onclick="toggleItem('table01')">LINK 01</a><br>
<table style="display:none; border-collapse: collapse" id="table01">
<tr>
<td> <a href="#">SUB LINK 01</a></td>
</tr>
<tr>
<td> <a href="#">SUB LINK 02</a></td>
</tr>
<tr>
<td> <a href="#">SUB LINK 03</a></td>
</tr>
</table>
<a href="#" onclick="toggleItem('table02')">LINK 02</a><br>
<table style="display:none; border-collapse: collapse" id="table02">
<tr>
<td> <a href="#">SUB LINK 01</a></td>
</tr>
<tr>
<td> <a href="#">SUB LINK 02</a></td>
</tr>
<tr>
<td> <a href="#">SUB LINK 03</a></td>
</tr>
</table>
</body>
</html>
With this setup, if you click on Link 01 it expands the table just fine. Click on it again and it collapses, exactly what I want it to do.
If you click on Link 01, it expands, but it click on Link 02, Link 01 remains open, and Link 02 Opens as well. I'd like Link 01 to close when Link 02 is clicked, and visa versa (no matter how may links and collapsable tables are on the page).
Lastly, I'd like the current selection to be passed on to the next page when loaded so the menu remains the same until the user changes the menu. I'd also like to do this without using frames if possible.
Any help? Remember, I'm a beginner so comments in the script explaining what is occuring would be greatly appreciated!!!!
Much thanks to anyone who helps!
DethanB