PDA

View Full Version : Drop-down menu Problem



mburt
08-12-2006, 10:23 PM
I've made a drop-down menu, and I keep getting an error saying "object required"

Here's the script:


<html>
<head>
<style type="text/css">
.header a:link {
padding:2px;
border:1px solid #000000;
background:#3399FF;
font:12px ms reference sans serif;
color:#000000;
text-decoration:none
}
.header a:visited {
padding:2px;
border:1px solid #000000;
background:#3399FF;
font:12px ms reference sans serif;
color:#000000;
text-decoration:none
}
.header a:active {
padding:2px;
border:1px solid #000000;
background:#3399FF;
font:12px ms reference sans serif;
color:#000000;
text-decoration:none
}
.header a:hover {
background:white
}
.menu {
width:100px;
border:1px solid black;
background:#3399FF;
font:12px ms reference sans serif;
padding:2px;
display:none;
position:absolute
}
</style>
<script type="text/javascript">
var i=0
var menus=new Array("menu1")
function showmenu(num) {
i=0
var obj=document.getElementById(menus[num])
obj.style.display="block"
obj.style.left=9
obj.style.top=37
clearTimeout(t1)
}
function hidemenu(num) {
var menus=new Array("menu1")
var obj=document.getElementById(menus[num])
if (obj.style.display=="block") {
i=i+1
if (i==2) {obj.style.display="none"}
}
t1=setTimeout("hidemenu()",1000)
}
window.onload=function() {hidemenu(0)}
</script>
</head>
<body>
<span class="header" onmouseover="showmenu(0)" onmouseout="hidemenu(0)">
<a href="#">Home</a>
</span>
<div class="menu" id="menu1" onmouseover="showmenu(0)" onmouseout="hidemenu(0)">
Menu Item 1
<br>Menu Item 2
</div>
</body>
</html>

Thanks

jscheuer1
08-13-2006, 06:45 AM
This is a little screwy:


function hidemenu(num) {
var menus=new Array("menu1")
var obj=document.getElementById(menus[num])
if (obj.style.display=="block") {
i=i+1
if (i==2) {obj.style.display="none"}
}
t1=setTimeout("hidemenu()",1000)
}

The first time through when called onload with:


window.onload=function() {hidemenu(0)}

it is mostly OK but, the second time, when it calls itself with no 'num' argument:


t1=setTimeout("hidemenu()",1000)

This gets executed:

var obj=document.getElementById(menus[])

which means nothing, then when it tries to do this:


if (obj.style.display=="block") {
i=i+1
if (i==2) {obj.style.display="none"}
}

obj has no properties.