Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy function target path

    hi, here's a JS file, which gives an error that 'menu1 is not defined'. I'm trying to make a drop down, which I'll be able to re-use anywhere in my site, but having trouble setting visibility, and suppose I'll have trouble passing the link names to the JS file. Help? ; )
    Jenny

    document.write("<style>table{font size:10pt}tr background:#209090}a{color:#000000; text-decoration:none; font:bold}a:hover{color:#FFFFFF}td.menu{background:408060; font-size:10pt; position:absolute; visibility:hidden; z-index=1000}</style>")

    function setVisibility (menuName)
    {
    menu1.onmouseover="document.subMenu1.style.visibility='visible'";
    menu1.onmouseout="document.subMenu1.style.visibility='hidden'";
    }

    document.write('<table cellpadding=0 cellspacing=0 border=0><tr>')
    document.write('<td id="menu1"')

    document.write('<table cellpadding=3 cellspacing=1 border="0" width=100%><tr>')
    document.write('<td nowrap><a href="../link1.html">Menu Item 1</a></td>')
    document.write('</tr></table>')

    document.write('<table cellpadding=3 cellspacing=1 border=0 class="menu" id="subMenu1" width=100%>')
    document.write('<tr><td class="menu"><a href="../html">HTML</a></td></tr>')
    document.write('<tr><td class="menu"><a href="../xhtml">XHTML</a></td></tr>')
    document.write('<tr><td class="menu"><a href="../css">CSS</a></td></tr>')
    document.write('<tr><td class="menu"><a href="../xml">XML</a></td></tr>')
    document.write('<tr><td class="menu"><a href="../xsl">XSL</a></td></tr>')
    document.write('</table>')

    document.write('</td></tr></table>')

    window.onload=setVisibility;

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In this function:

    Code:
    function setVisibility (menuName) 
    { 
    function setVisibility (menuName) 
    { 
    menu1.onmouseover="document.subMenu1.style.visibility='visible'"; 
    menu1.onmouseout="document.subMenu1.style.visibility='hidden'"; 
    } 
    ="document.subMenu1.style.visibility='visible'"; 
    menu1.onmouseout="document.subMenu1.style.visibility='hidden'"; 
    }
    Why pass "menuName" and then not use it within the code?

    Where you have menu1.onmouseover you should have document.getElementById('menu1').onmouseover and then you're just setting the event to a string which is also wrong (it may look like code but it's just a string", you need to set the event to a function.

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was sending the variable because there might be more than one drop-down, and because the actual links will have to be passed through also. I did not understand your answer... 'you need to set the event to a function.' I am trying to write a function...
    pls, if you could explain? thx!


  •  

    Posting Permissions

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