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 6 of 6

Thread: popup menu help

  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry popup menu help

    I need help with this popup menu. I type in my javascrpt (using getElementById), test the page and... nothing.

    head code:
    <script>
    function showMenu(object) {
    if (toClose == 1) {
    document.getElementById(oldMenu).style.visibility = "hidden";
    }


    document.getElementById(obj).style.visibility ="visable";
    oldMenu = object;
    }

    closing(object, standby);

    function closing(object, mode) {
    if (mode == "standby") {
    settimeout("closing(object, close)", 3000);
    }
    if(mode == "close") {
    document.getElementById(object).style.visibility = "hiddin";
    if(mode == "wate") {
    settimeout("closing(object, wate)", 0000);
    }
    </script>
    <style>
    #menu1,#menu2,#menu3,#menu4,#menu5 {
    position: absolute;
    top: -100px;
    left: 100px;
    visibility: hidden;
    background-color:black;
    color:yellow;
    </style>
    body:
    [quote]
    ...

    <table width="20%" bgcolor="yellow">
    <tr>
    <td>
    <a href="#" oncick="showMenu(menu1)">Menu 1</a><br>
    <a href="#" onclick="showMenu(menu2)">Menu 2</a><br>
    <a href="#" onclick="showMunu(menu3)">Menu 3</a><br>
    <a href="#" onclick="showMenu(menu4)">Menu 4</a><br>
    <a href="#" onclick="showMenu(menu5)">Menu 5</a><br><br><br>
    <img src="http://jigsaw.w3.org/css-validator/images/vcss">


    </td>







    </table>
    </table>

    <div id="menu1">
    menu 1
    </div>
    <div id="menu2">
    menu2
    </div>
    <div id="menu3">
    menu3
    </div>
    <div id="menu4">
    menu4</div>
    <div id="menu5">
    menu 5</div>
    ...[quote]

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    'visable' and 'hidin' should be 'visible' and 'hidden'.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My problem still remains

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Yeah, you have a problem with the setTimeouts and closing calls too. standby should be 'standby', close should be 'close', wate should be 'wate'.

    But that isn't enough. You are trying to call the closing function with the local variable object in the timeout, but the timeout is executed in the global scope, not in the local scope, and thus it can't get at the local object variable. You need to eliminate those problems, and the way I would use would be closures, like this:
    Code:
    function fnCreateClosure( oElement, sMode ){
        return function (){
            closing( oElement, sMode );
        }
    }
    Using this function, you should change your setTimeouts to look like this example:
    Code:
    setTimeout( fnCreateClosure(object, 'close'), 3000 );
    Last edited by liorean; 01-11-2004 at 09:47 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by liorean
    Yeah, you have a problem with the setTimeouts and closing calls too. standby should be 'standby', close should be 'close', wate should be 'wate'.

    But that isn't enough. You are trying to call the closing function with the local variable object in the timeout, but the timeout is executed in the global scope, not in the local scope, and thus it can't get at the local object variable. You need to eliminate those problems, and the way I would use would be closures, like this:
    Code:
    function fnCreateClosure( oElement, sMode ){
        return function (){
            closing( oElement, sMode );
        }
    }
    Using this function, you should change your setTimeouts to look like this example:
    Code:
    setTimeout( fnCreateClosure(object, 'close'), 3000 );
    And still, the menus won't open.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    getElementByID() wants a string as an input parameter. It looks like you're sending an object (oldMenu). You need to pass the ID of the desired tag either as a string literal or in a string variable.


  •  

    Posting Permissions

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