Andrew Green
02-17-2006, 04:39 PM
Nice and simple, hopefully easy to understand javascript menu's.
Not the most elaberate system, no nesting, but it is functional and fairly simple (hopefully)
See next post for explanation.
<html>
<head>
<style type="text/css">
a{
color:white;
}
</style>
<script type="text/javascript">
var menuactive = -1
var submenus = new Array()
submenus[0] = "sub1"
submenus[1] = "sub2"
var parmenus = new Array()
parmenus[0] = "par1"
parmenus[1] = "par2"
function menusetup()
{
for (var i=0;i<submenus.length;i++)
{
document.getElementById(submenus[i]).style.cursor="pointer"
}
for (var i=0;i<parmenus.length;i++)
{
document.getElementById(parmenus[i]).style.cursor="pointer"
}
}
function activatesubmenu(z,x)
{
for (var i=0;i<submenus.length;i++)
{
if (z==-1)
{
document.getElementById(submenus[i]).style.visibility="hidden"
document.getElementById(parmenus[i]).style.backgroundColor='transparent'
menuactive=-1
}
if (z==1)
{
if (x==i)
{
if (document.getElementById(submenus[i]).style.visibility=="visible")
{
document.getElementById(submenus[i]).style.visibility="hidden"
menuactive=-1
}
else
{
document.getElementById(submenus[i]).style.visibility="visible"
menuactive=i
}
}
else
{
document.getElementById(submenus[i]).style.visibility="hidden"
}
}
else if (z==0)
{
if(menuactive >-1)
{
if (menuactive!=x)
{
document.getElementById(submenus[menuactive]).style.visibility="hidden"
document.getElementById(submenus[x]).style.visibility="visible"
menuactive=x
}
}
if (x==i)
{
document.getElementById(parmenus[i]).style.backgroundColor='#707070'
}
else
{
document.getElementById(parmenus[i]).style.backgroundColor='transparent'
}
}
}
}
</script>
</head>
<body onload='menusetup()'>
<table id="sub1" style="visibility:hidden;z-index:1;background-color:#000000;position:absolute;top:50px;left:50px ;" cellpadding =" 0px" cellspacing="0px">
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page1a'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1a" onClick="return false">Page 1a</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page1b'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1b" onClick="return false">page 1b</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page1c'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1c" onClick="return false">Page 1c</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page1d'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1d" onClick="return false">Page 1d</a></td></tr>
</table>
<table id="sub2" style="visibility:hidden;z-index:1;background-color:#000000;position:absolute;top:50px;left:300p x;" cellpadding =" 0px" cellspacing="0px">
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page2a'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1a" onClick="return false">Page 2a</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page2b'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1b" onClick="return false">page 2b</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page2c'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1c" onClick="return false">Page 2c</a></td></tr>
</table>
<table style="position:absolute;top:25px;left:50px;height:25px;p adding: 0px 0px 0px 0px;background-color:black" >
<tr>
<td id="par1" style="border-bottom:thin solid #b0b0b0;width:246px;" onClick="activatesubmenu(1,0)" onmouseover="activatesubmenu(0,0)">
<a class="nav2" href="index.php?action=page1&nojava=1" onClick="return false">menu heading</a>
</td>
<td id="par2" style="border-bottom:thin solid #b0b0b0;width:246px;" onClick="activatesubmenu(1,1)" onmouseover="activatesubmenu(0,1)">
<a class="nav2" href="index.php?action=page2&nojava=1" onClick="return false">menu heading</a>
</td>
</tr>
</table>
</body>
</html>
Not the most elaberate system, no nesting, but it is functional and fairly simple (hopefully)
See next post for explanation.
<html>
<head>
<style type="text/css">
a{
color:white;
}
</style>
<script type="text/javascript">
var menuactive = -1
var submenus = new Array()
submenus[0] = "sub1"
submenus[1] = "sub2"
var parmenus = new Array()
parmenus[0] = "par1"
parmenus[1] = "par2"
function menusetup()
{
for (var i=0;i<submenus.length;i++)
{
document.getElementById(submenus[i]).style.cursor="pointer"
}
for (var i=0;i<parmenus.length;i++)
{
document.getElementById(parmenus[i]).style.cursor="pointer"
}
}
function activatesubmenu(z,x)
{
for (var i=0;i<submenus.length;i++)
{
if (z==-1)
{
document.getElementById(submenus[i]).style.visibility="hidden"
document.getElementById(parmenus[i]).style.backgroundColor='transparent'
menuactive=-1
}
if (z==1)
{
if (x==i)
{
if (document.getElementById(submenus[i]).style.visibility=="visible")
{
document.getElementById(submenus[i]).style.visibility="hidden"
menuactive=-1
}
else
{
document.getElementById(submenus[i]).style.visibility="visible"
menuactive=i
}
}
else
{
document.getElementById(submenus[i]).style.visibility="hidden"
}
}
else if (z==0)
{
if(menuactive >-1)
{
if (menuactive!=x)
{
document.getElementById(submenus[menuactive]).style.visibility="hidden"
document.getElementById(submenus[x]).style.visibility="visible"
menuactive=x
}
}
if (x==i)
{
document.getElementById(parmenus[i]).style.backgroundColor='#707070'
}
else
{
document.getElementById(parmenus[i]).style.backgroundColor='transparent'
}
}
}
}
</script>
</head>
<body onload='menusetup()'>
<table id="sub1" style="visibility:hidden;z-index:1;background-color:#000000;position:absolute;top:50px;left:50px ;" cellpadding =" 0px" cellspacing="0px">
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page1a'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1a" onClick="return false">Page 1a</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page1b'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1b" onClick="return false">page 1b</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page1c'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1c" onClick="return false">Page 1c</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page1d'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1d" onClick="return false">Page 1d</a></td></tr>
</table>
<table id="sub2" style="visibility:hidden;z-index:1;background-color:#000000;position:absolute;top:50px;left:300p x;" cellpadding =" 0px" cellspacing="0px">
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page2a'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1a" onClick="return false">Page 2a</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page2b'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1b" onClick="return false">page 2b</a></td></tr>
<tr><td style="width:250px;height:25px;border:thin solid #b0b0b0;" onclick="parent.location='index.php?action=page2c'" onmouseover="this.style.backgroundColor='#707070'" onmouseout="this.style.backgroundColor='#000000'"><a class="nav2" href="index.php?action=page1c" onClick="return false">Page 2c</a></td></tr>
</table>
<table style="position:absolute;top:25px;left:50px;height:25px;p adding: 0px 0px 0px 0px;background-color:black" >
<tr>
<td id="par1" style="border-bottom:thin solid #b0b0b0;width:246px;" onClick="activatesubmenu(1,0)" onmouseover="activatesubmenu(0,0)">
<a class="nav2" href="index.php?action=page1&nojava=1" onClick="return false">menu heading</a>
</td>
<td id="par2" style="border-bottom:thin solid #b0b0b0;width:246px;" onClick="activatesubmenu(1,1)" onmouseover="activatesubmenu(0,1)">
<a class="nav2" href="index.php?action=page2&nojava=1" onClick="return false">menu heading</a>
</td>
</tr>
</table>
</body>
</html>