Javascript switch menu please help

Discussion in 'Software' started by skibum, Apr 21, 2005.

  1. skibum

    skibum Private E-2

    I have this great script which I downloaded from http://getElementById.com

    The problem is very simple - my links actually load new pages, and resets the menu. I would like the submenus to stay visible on the new page. I am not very familiar with javascript, and I was wondering if someone could help me!
    I've included the script and also a sample from the html body.

    <script type="text/javascript">
    /*
    Script made by Martial Boissonneault © 2001-2003 http://getElementById.com/
    This script may be used and changed freely as long as this msg is intact
    Visit http://getElementById.com/ for more free scripts and tutorials.
    */
    function SwitchMenu(obj){
    if(document.getElementById){
    var el = document.getElementById(obj);
    var ar = document.getElementById("cont").getElementsByTagName("DIV");
    if(el.style.display == "none"){
    for (var i=0; i<ar.length; i++){
    ar.style.display = "none";
    }
    el.style.display = "block";
    }else{
    el.style.display = "none";
    }
    }
    }
    function ChangeClass(menu, newClass) {
    if (document.getElementById) {
    document.getElementById(menu).className = newClass;
    }
    }
    document.onselectstart = new Function("return false");

    </script>

    from the body....

    <div id="cont">
    <p id="menu1" class="menuOut" onclick="SwitchMenu('sub1')" onmouseover="ChangeClass('menu1','menuOver')" onmouseout="ChangeClass('menu1','menuOut')"><a href="main.php"><img src="button_home.gif"></a></p>


    <p id="menu2" class="menuOut" onclick="SwitchMenu('sub2')" onmouseover="ChangeClass('menu2','menuOver')" onmouseout="ChangeClass('menu2','menuOut')"><img src="button_info.gif"></a></p>
    <div class="submenu" id="sub2" style="display:none;">
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds