Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Help with Sub Sub Menu

  1. #1
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with Sub Sub Menu

    I am using the following code and need help in creating submenus. For example, under "Site Menu" I want to create a submenu "More Links" with selections under it such as yahoo.com, hnc.com, etc.

    Additionally, there are times I need to create a submenu of the submenu. For example: "Process & Procedures" would be the main menu. "Paperwork Process" would be a submenu under "Process & Procedures" and "New Contract Process" would be a submenu under "Paperwork Process".

    Here is the code used from dynamicdrive.com:

    <style type="text/css">
    .menutitle{
    cursorointer;
    margin-bottom: 5px;
    background-color:#ECECFF;
    color:#000000;
    width:140px;
    padding:2px;
    text-align:center;
    font-weight:bold;
    /*/*/border:1px solid #000000;/* */
    }

    .submenu{
    margin-bottom: 0.5em;
    }
    </style>

    <script type="text/javascript">

    /***********************************************
    * Switch Menu script- by Martial B of http://getElementById.com/
    * Modified by Dynamic Drive for format & NS4/IE4 compatibility
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
    var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

    if (document.getElementById){ //DynamicDrive.com change
    document.write('<style type="text/css">\n')
    document.write('.submenu{display: none;}\n')
    document.write('</style>\n')
    }

    function SwitchMenu(obj){
    if(document.getElementById){
    var el = document.getElementById(obj);
    var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
    if(el.style.display != "block"){ //DynamicDrive.com change
    for (var i=0; i<ar.length; i++){
    if (ar[i].className=="submenu") //DynamicDrive.com change
    ar[i].style.display = "none";
    }
    el.style.display = "block";
    }else{
    el.style.display = "none";
    }
    }
    }

    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }

    function onloadfunction(){
    if (persistmenu=="yes"){
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=get_cookie(cookiename)
    if (cookievalue!="")
    document.getElementById(cookievalue).style.display="block"
    }
    }

    function savemenustate(){
    var inc=1, blockid=""
    while (document.getElementById("sub"+inc)){
    if (document.getElementById("sub"+inc).style.display=="block"){
    blockid="sub"+inc
    break
    }
    inc++
    }
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
    document.cookie=cookiename+"="+cookievalue
    }

    if (window.addEventListener)
    window.addEventListener("load", onloadfunction, false)
    else if (window.attachEvent)
    window.attachEvent("onload", onloadfunction)
    else if (document.getElementById)
    window.onload=onloadfunction

    if (persistmenu=="yes" && document.getElementById)
    window.onunload=savemenustate

    </script>

    <!-- Keep all menus within masterdiv-->
    <div id="masterdiv">

    <div class="menutitle" onclick="SwitchMenu('sub1')">Site Menu</div>
    <span class="submenu" id="sub1">
    - <a href="new.htm">What's New</a><br>
    - <a href="hot.htm">What's hot</a><br>
    - <a href="revised.htm">Revised Scripts</a><br>
    - <a href="morezone/">More Zone</a>
    </span>

    <div class="menutitle" onclick="SwitchMenu('sub2')">FAQ/Help</div>
    <span class="submenu" id="sub2">
    - <a href="notice.htm">Usage Terms</a><br>
    - <a href="faqs.htm">DHTML FAQs</a><br>
    - <a href="help.htm">Scripts FAQs</a>
    </span>

    <div class="menutitle" onclick="SwitchMenu('sub3')">Help Forum</div>
    <span class="submenu" id="sub3">
    - <a href="http://www.codingforums.com">Coding Forums</a><br>
    </span>

    <div class="menutitle" onclick="SwitchMenu('sub4')">Cool Links</div>
    <span class="submenu" id="sub4">
    - <a href="http://www.javascriptkit.com">JavaScript Kit</a><br>
    - <a href="http://www.freewarejava.com">Freewarejava</a><br>
    - <a href="http://www.cooltext.com">Cool Text</a><br>
    - <a href="http://www.google.com">Google.com</a>
    </span>

    <img src="about.gif" onclick="SwitchMenu('sub5')"><br>
    <span class="submenu" id="sub5">
    - <a href="http://www.dynamicdrive.com/link.htm">Link to DD</a><br>
    - <a href="http://www.dynamicdrive.com/recommendit/">Recommend Us</a><br>
    - <a href="http://www.dynamicdrive.com/contact.htm">Email Us</a><br>
    </span>

    </div>

  2. #2
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Switchmenu Sub Menu Help Please...

    Author: MartialB
    http://www.dynamicdrive.com/dynamici...switchmenu.htm

    I am using the following code and need help in creating submenus. For example, under "Site Menu" I want to create a submenu "More Links" with selections under it such as yahoo.com, hnc.com, etc.

    Additionally, there are times I need to create a submenu of the submenu. For example: "Process & Procedures" would be the main menu. "Paperwork Process" would be a submenu under "Process & Procedures" and "New Contract Process" would be a submenu under "Paperwork Process".

    Here is the code used from dynamicdrive.com:

    <style type="text/css">
    .menutitle{
    cursorointer;
    margin-bottom: 5px;
    background-color:#ECECFF;
    color:#000000;
    width:140px;
    padding:2px;
    text-align:center;
    font-weight:bold;
    /*/*/border:1px solid #000000;/* */
    }

    .submenu{
    margin-bottom: 0.5em;
    }
    </style>

    <script type="text/javascript">

    /***********************************************
    * Switch Menu script- by Martial B of http://getElementById.com/
    * Modified by Dynamic Drive for format & NS4/IE4 compatibility
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
    var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

    if (document.getElementById){ //DynamicDrive.com change
    document.write('<style type="text/css">\n')
    document.write('.submenu{display: none;}\n')
    document.write('</style>\n')
    }

    function SwitchMenu(obj){
    if(document.getElementById){
    var el = document.getElementById(obj);
    var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
    if(el.style.display != "block"){ //DynamicDrive.com change
    for (var i=0; i<ar.length; i++){
    if (ar[i].className=="submenu") //DynamicDrive.com change
    ar[i].style.display = "none";
    }
    el.style.display = "block";
    }else{
    el.style.display = "none";
    }
    }
    }

    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }

    function onloadfunction(){
    if (persistmenu=="yes"){
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=get_cookie(cookiename)
    if (cookievalue!="")
    document.getElementById(cookievalue).style.display="block"
    }
    }

    function savemenustate(){
    var inc=1, blockid=""
    while (document.getElementById("sub"+inc)){
    if (document.getElementById("sub"+inc).style.display=="block"){
    blockid="sub"+inc
    break
    }
    inc++
    }
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
    document.cookie=cookiename+"="+cookievalue
    }

    if (window.addEventListener)
    window.addEventListener("load", onloadfunction, false)
    else if (window.attachEvent)
    window.attachEvent("onload", onloadfunction)
    else if (document.getElementById)
    window.onload=onloadfunction

    if (persistmenu=="yes" && document.getElementById)
    window.onunload=savemenustate

    </script>

    <!-- Keep all menus within masterdiv-->
    <div id="masterdiv">

    <div class="menutitle" onclick="SwitchMenu('sub1')">Site Menu</div>
    <span class="submenu" id="sub1">
    - <a href="new.htm">What's New</a><br>
    - <a href="hot.htm">What's hot</a><br>
    - <a href="revised.htm">Revised Scripts</a><br>
    - <a href="morezone/">More Zone</a>
    </span>

    <div class="menutitle" onclick="SwitchMenu('sub2')">FAQ/Help</div>
    <span class="submenu" id="sub2">
    - <a href="notice.htm">Usage Terms</a><br>
    - <a href="faqs.htm">DHTML FAQs</a><br>
    - <a href="help.htm">Scripts FAQs</a>
    </span>

    <div class="menutitle" onclick="SwitchMenu('sub3')">Help Forum</div>
    <span class="submenu" id="sub3">
    - <a href="http://www.codingforums.com">Coding Forums</a><br>
    </span>

    <div class="menutitle" onclick="SwitchMenu('sub4')">Cool Links</div>
    <span class="submenu" id="sub4">
    - <a href="http://www.javascriptkit.com">JavaScript Kit</a><br>
    - <a href="http://www.freewarejava.com">Freewarejava</a><br>
    - <a href="http://www.cooltext.com">Cool Text</a><br>
    - <a href="http://www.google.com">Google.com</a>
    </span>

    <img src="about.gif" onclick="SwitchMenu('sub5')"><br>
    <span class="submenu" id="sub5">
    - <a href="http://www.dynamicdrive.com/link.htm">Link to DD</a><br>
    - <a href="http://www.dynamicdrive.com/recommendit/">Recommend Us</a><br>
    - <a href="http://www.dynamicdrive.com/contact.htm">Email Us</a><br>
    </span>

    </div>

  3. #3
    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

    Have a look at this demo.
    - John
    ________________________

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

  4. #4
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thank you

    Thank you jscheuer1! It is exactly what I was looking for.

  5. #5
    Join Date
    Oct 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello, I need exactly the demo but with one more level... I need a menu, a submenu and a subsubmenu (3 levels)... what changes should I do on the code to do this? Please help me!!!!!

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

    Default

    That code doesn't have a third-level function. There are scripts that do have multi-levels on DynamicDrive
    - Mike

  7. #7
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the script. It solved my problem. One question though, How do I use external CSS file? What change do I have to make to the following lines in the script?
    if (document.getElementById){ //DynamicDrive.com change
    document.write('<style type="text/css">\n')
    document.write('.month{display: none;}\n')
    document.write('.week{display: none;}\n')
    document.write('</style>\n')
    }


    Thanks again.

  8. #8
    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

    No change is required. Use your external css file as you normally would.
    - John
    ________________________

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

  9. #9
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Eh, I'm not sure if you're referring to the styling printed there or another stylesheet that's totally unrelated, but if it's the former, do this instead:

    Code:
    if (document.getElementById){ //DynamicDrive.com change
    document.write('<style type="text/css">\n')
    document.write('@import url('ddcss.css');\n')
    document.write('</style>\n')
    }
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  10. #10
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot. However, I got another question.

    Is it possible to reuse ssub1, ssub2 in different sub? i.e: sub2, sub3.
    I have customize the script according to my needs, howver i dont know much about programing. If you like I can paste the whole thing here and explain more, if that helps.

    Thanks again.

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
  •