menues and submenu

Discussion in 'JavaScript' started by bogdan911, Jan 9, 2009.

  1. #1
    hi. i have this html code:
    
        <div class="menu_left">
         <ul><li><a id="cat1" class="catlink" href="detalii.php" title="" onclick="java script:return togglethis(this,true);">Institutii</a>
    <ul class="menu_left_subsection hide"><li id="subcat0">
             <a href=utile.php?idsubmeniu=1&idjudet=1>Institutii&nbsp;</a></li>
             <li id="subcat1">
             <a href=utile.php?idsubmeniu=2&idjudet=1>relatii publice&nbsp;</a></li>
             </ul></li><li><a id="cat2" class="catlink" href="detalii.php" title="" onclick="java script:return togglethis(this,true);">Institutii2</a>
    
    <ul class="menu_left_subsection hide"><li id="subcat2">
             <a href=utile.php?idsubmeniu=3&idjudet=1>primarii&nbsp;</a></li>
             </ul></li></ul> <br><br><Br><form action=search.php method=get>
    <input type=text name=searchfield size=23>
    <input type=submit value=cauta>
    </form>
                           <a href=contact.php>Contact</a>  
                             </div>
    
    HTML:
    and meniu.js:
    
    function setCookie(name,value,expires,path,domain,secure){
        var today=new Date();
        today.setTime(today.getTime());
        if(!path)path='/';
        if(expires){
            expires = expires*1000*60*60*24;
        }
        var expires_date = new Date(today.getTime()+(expires));
        document.cookie = name+"="+escape(value)+(expires?";expires="
                        +expires_date.toGMTString():"")+(path?";path="+path:"")
                        +(domain?";domain="+domain:"")+(secure?";secure":"");
    }
    
    function getCookie(name,def){
        var cs=document.cookie.split("; ");
        for(var i=0;i<cs.length;i++){
            var c=cs[i].split("=");
            if(name==c[0])
                return unescape(c[1]);
        }
        return def;
    }
    
    function togglethis(el,mode){
        var ul=el.parentNode.parentNode;
        var csec=getCookie('current_sec',null);
        document.cookie='current_sec='+el.id;
      
        for(i in ul.childNodes){
            if(ul.childNodes[i].nodeType=='1'){
                if(ul.childNodes[i].childNodes[0].id==el.id){
                    ul.childNodes[i].childNodes[0].className='catlink act';
                    for(j in ul.childNodes[i].childNodes){
                        if(ul.childNodes[i].childNodes[j].nodeName=='UL'){
                            if(el.id==csec&&mode==true){
                                ul.childNodes[i].childNodes[j].className='menu_left_subsection hide';
                                ul.childNodes[i].childNodes[0].className='catlink';
                                document.cookie='current_sec=';
                            }else{
                                ul.childNodes[i].childNodes[j].className='menu_left_subsection'
                                }
                        }
                    }
                }else{
                    ul.childNodes[i].childNodes[0].className='catlink';
                    for(j in ul.childNodes[i].childNodes){
                        if(ul.childNodes[i].childNodes[j].nodeName=='UL'){
                            ul.childNodes[i].childNodes[j].className='menu_left_subsection hide';
                        }
                    }
                }
            }
        }
        return false;
    }
    
    Code (markup):
    this script is a menu with menus and submenus, when i click on a menu, it expands and it shows the submenus.. the problem is when i refresh the page, the menu will not stay expanded...
    meniu.js is creating a cookie called current_sec with the menu id, i'ved tried to add in <body> to be like this:<body onload="javascript: return togglethis('cat1',true);"> but it doesn't work.
    Can someone help me?
     
    bogdan911, Jan 9, 2009 IP