Results 1 to 2 of 2

Thread: Drop-down menu Problem

  1. #1
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default Drop-down menu Problem

    I've made a drop-down menu, and I keep getting an error saying "object required"

    Here's the script:

    Code:
    <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
    - Mike

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This is a little screwy:

    Code:
    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:

    Code:
    window.onload=function() {hidemenu(0)}
    it is mostly OK but, the second time, when it calls itself with no 'num' argument:

    Code:
    t1=setTimeout("hidemenu()",1000)
    This gets executed:

    var obj=document.getElementById(menus[])

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

    Code:
    if (obj.style.display=="block") {
    i=i+1
    if (i==2) {obj.style.display="none"}
    }
    obj has no properties.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •