Beginner Help with toggle menu on and off

Discussion in 'JavaScript' started by frequenC, Jun 24, 2007.

  1. #1
    Hi
    I have a menu that opens and shuts on click using the code at the bottom, js and html:

    What I am trying to achieve is when you click the toggle link <a href="javascript:toggle('menu1')" class="folder">Main Home</a>

    The link goes to the relevant page and expands the menu on that page, at present it opens on the same page the menu is on.

    I would appreciate any help in achieveing this

    Thank you,

    frequenC

    <!--Script to click expand menu-->
    <script type="text/javascript">
    document.getElementById('leftMenu').style.listStyle="none";
    document.getElementById('menu1').style.display="none";
    document.getElementById('menu2').style.display="none";
    document.getElementById('menu3').style.display="none";
    function toggle(list){
    var listElementStyle=document.getElementById(list).style;
    if (listElementStyle.display=="none"){
    listElementStyle.display="block";
    }
    else{ listElementStyle.display="none";
    }
    }

    </script>



    <!--HML-->
    <ul id="leftMenu">
    <li> <a href="javascript:toggle('menu1')" class="folder">Main Home</a>
    <li id="menu1">
    <ul style="margin-top:-15px">
    <li><a href="#">BR Home</a></li>
    <li><a href="#">About BR</a></li>
    </ul></li>
    <li><a href="javascript:toggle('menu2')" class="folder">PNC</a>
    <li id="menu2">
    <ul style="margin-top:-15px">
    <li><a href="#">Home</a></li>
    <li><a href="#">About Us</a></li>
    <li><a href="#">Toolkit</a></li>
    <li><a href="#" target="_blank">Leading Practices Library</a></li>
    <li><a href="#" target="_blank">Results</a></li> </ul></li>
    <li><a href="javascript:toggle('menu3')" class="folder">Planning</a>
    <li id="menu3">
    <ul style="margin-top:-15px">
    <li><a href="/bhpboe/opencms/Business_Planning/index.html">planning Home</a></li>
    <li><a href="#">The Way of Planning</a></li>
    <li><a href="#">FAQs</a></li>
    <li><a href="#">&quot;How To&quot; Guides </a></li>
    <li><a href="#">Training Dates</a></li>
    </ul></li></ul>
     
    frequenC, Jun 24, 2007 IP
  2. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    I'm sorry, but I don't really get it. Do you want another page to open? another window? layer?
     
    NoamBarz, Jun 25, 2007 IP
  3. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    isn't that just the point of having a dropdown list?
    if you just want to display the options from the menu on the actual page the visitor wants to visit, then there's no point using it ;)
     
    UnrealEd, Jun 25, 2007 IP
  4. frequenC

    frequenC Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Currently it just toggles the menu I would like it to work so that when the menu item with the toggle attached is clicked it launches the new page and then the menu item expands in the new page.

    So how do I add a link to main Home tab to open the main home page and then the menu expanding to show the BR Home and About BR links.

    <li> <a href="javascript:toggle('menu1')" class="folder">Main Home</a>
    <li id="menu1">
    <ul style="margin-top:-15px">
    <li><a href="#">BR Home</a></li>
    <li><a href="#">About BR</a></li>
    </ul></li>
     
    frequenC, Jun 26, 2007 IP
  5. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i'd go for AJAX: instead of redirecting the user to the home page, you open the page inside the current one by loading it into a div (or iframe, but i would use a div). Search google for "AJAX tutorials", and i'm sure you'll find what you need
     
    UnrealEd, Jun 28, 2007 IP
  6. frequenC

    frequenC Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for pointing me in the right direction :)
     
    frequenC, Jun 28, 2007 IP