javascript menu


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: javascript menu

  1. #1
    sks Guest

    javascript menu


    Hello,
    I have a working javascript menu, similar to a tree menu. If I click on a
    submenu, the page refreshes and shows content related to the link i clicked.
    Now, what i need is for that submenu whose link i clicked to stay open and
    all other submenus to close. This should happen only when i click on a link
    of a submenu otherwise any submenu opened before can stay open. How do i
    do that? I think the function has to be in an onclick event of individual
    links of the submenus, right?

    (title and submenu is defined in a css file as classes)

    .js code:
    _____________
    // The main script for toggling the selected menu
    // Input variables:
    // n = the number of the submenu to show/hide
    // move = the number of pixels for moving the objects below

    function toggle(n,move) {
    menu = ('submenu' + n);
    if (document.layers) {
    submenu = document.layers[menu];
    }
    else if (document.all) {
    submenu = document.all(menu).style;
    }
    if (submenu.visibility == visible) {
    submenu.visibility = hidden;
    picclose(n);
    for (var i = (n+1); i <= nom; i++) {
    if (document.layers) {
    document.layers[tits[i]].top -= move;
    document.layers[subs[i]].top -= move;
    }
    else if (document.all) {
    document.all(tits[i]).style.pixelTop -= move;
    document.all(subs[i]).style.pixelTop -= move;
    }
    }
    }
    else {
    submenu.visibility = visible;
    picopen(n);
    for (var i = (n+1); i <= nom; i++) {
    if (document.layers) {
    document.layers[tits[i]].top += move;
    document.layers[subs[i]].top += move;
    }
    if (document.all) {
    document.all(tits[i]).style.pixelTop += move;
    document.all(subs[i]).style.pixelTop += move;
    }
    }
    }
    }


    document.write( '<div class="title" id="title2" style="top: 160px">' );
    document.write( '<a href="#" onclick="javascript: toggle(2,60); return false"><img
    name="pic2" src="images/closed.gif" border="0" hspace="2">Papalim </a>' );

    document.write( '</div>' );

    document.write( '<div class="submenu" id="submenu2" style="top: 180px" onclick="javascript:
    showMenu(this);">' );
    document.write( '<a href="SampleTree.html">Papa 2</a><br>' );
    document.write( '<a href="SampleTree.html">Papa 3</a><br>' );
    document.write( '</div>' );

    Thank you,
    sks

    Share on Google+

  2. #2
    sks Guest

    Re: javascript menu


    Hi,

    The above problem works in IE 5.5! But, I just tested it in netscape 4.74;
    It just shows ALL the menu and submenu's and that's it. Could there be a
    problem in my css document? The hover affect in css doesn't work just as
    onclick in javascript doesn't work.

    Probably some features that i'm using may not be supported by my browser
    (IE 5.5, NES 4.74). I should be using IE 5.0 and NES 4.5 because that's what
    the client is going to be using. I haven't tested this problem in netscape
    4.5 yet.
    Any help will be appreciated!

    thanx,
    sks
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center