Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Cookies

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Detroit MI
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookies

    I'm trying to make a cookie that will remember the whether the menu was expanded or not.

    Here is the script to make the menu expand/contract:
    Code:
    function show(sub) {
    x = document.getElementById(sub).style.display;
    if (x=="") {
    document.getElementById(sub).style.display = "none";
    }else{
    document.getElementById(sub).style.display = "";
    }
    }
    How I am trying to set the cookie:
    Code:
    cookie_name = "dataCookie";
    var SubCook1;
    var SubCook2;
    var SubCook3;
    var SubCook4;
    
    function putCookie() {
    
    if(document.cookie != document.cookie) 
    {index = document.cookie.indexOf(cookie_name);}
    else 
    { index = -1;}
    
    if (index == -1)
    {
    SubCook1=document.getElementById('submenu1').style.display
    SubCook2=document.getElementById('submenu2').style.display
    SubCook3=document.getElementById('submenu3').style.display
    SubCook4=document.getElementById('submenu4').style.display
    document.cookie=cookie_name+"="+SubCook1+"; 
    document.cookie=cookie_name+"="+SubCook2+"; 
    document.cookie=cookie_name+"="+SubCook3+"; 
    document.cookie=cookie_name+"="+SubCook4+"; 
    }
    
    }
    How I am trying to get the cookies:
    Code:
    cookie_name = "dataCookie";
    var GetCook1;
    
    function getCook1() {
        if(document.cookie)
       {
            index = document.cookie.indexOf(cookie_name);
            if (index != -1)
         {
                namestart = (document.cookie.indexOf("=", index) + 1);
                nameend = document.cookie.indexOf(";", index);
                if (nameend == -1) {nameend = document.cookie.length;}
                YouWrote = document.cookie.substring(namestart, nameend);
                return SubCook1;
               }
            }
    }
    
    SubCook1=getCook1();
    
    if (SubCook1 == "dataCookie")
      {SubCook1 = "Nothing_Entered"}
    That is just for SubCook1 of course, I have the same thing for 2, 3 and 4 with the numbers changed.

    I think im way off on this....
    weirdness

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    627
    Thanks
    1
    Thanked 20 Times in 20 Posts
    You might find something helpfull on the "Samples of my work > Cookies" page at my site. The site address is:

    http://spruce.flint.umich.edu/~jalarie/

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    Detroit MI
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmmm...alright, I have no idea what any of that means...

    This is why I don't try to write my own cookie code...
    weirdness


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •