Setting cookie works, editing doesn't

Discussion in 'Javascript' started by ca@psver.net, Mar 1, 2006.

  1. Guest

    I'm using about 30 blocks with links on my page, that can be opened or
    closed by users so they're able to select which links should be
    displayed on their 'personal' page.

    Just closing blocks for the first time works fine, but returning
    visitors that want to open or close a new block, lose their first
    setting, everything in the cookie is replaced.

    I use this code, anyone got an idea? I spent days figuring it out! It
    drives me crazy!

    function toggle(t) {

    var para=document.getElementById(t);
    var tb = document.getElementById('t' + t);
    var htb = document.getElementById('h' + t);

    var v = GetCookieOpenClose('l');

    if(para.style.display!='none') {

    para.style.display = 'none';
    tb.style.display = 'block';
    htb.style.display = 'none';

    if (v!=null) {
    v += "|" + t;
    } else {

    v = "|" + t;
    }

    SetCookieOpenClose('l',v);

    }
    else {

    para.style.display = 'block';
    tb.style.display = 'none';
    htb.style.display = 'block';

    if (v!=null) {
    v = v.Replace("|" + t,"");
    }

    SetCookieOpenClose('l',v);

    }

    v = GetCookieOpenClose('l');

    return true;
    }
     
    , Mar 1, 2006
    #1
    1. Advertising

  2. wrote:

    [pretty printed:]
    > function toggle(t)
    > {
    > var para= document.getElementById(t);
    > var tb = document.getElementById('t' + t);
    > var htb = document.getElementById('h' + t);


    You have feature-tested the method before you call it, yes?

    > var v = GetCookieOpenClose('l');
    >
    > if (para.style.display!='none')
    > {
    > para.style.display = 'none';
    > tb.style.display = 'block';
    > htb.style.display = 'none';
    >
    > if (v!=null)
    > {
    > v += "|" + t;
    > }
    > else
    > {
    > v = "|" + t;
    > }
    >
    > SetCookieOpenClose('l',v);
    > }
    > else
    > {
    > para.style.display = 'block';
    > tb.style.display = 'none';
    > htb.style.display = 'block';
    >
    > if (v!=null)
    > {
    > v = v.Replace("|" + t,"");
    > }
    >
    > SetCookieOpenClose('l',v);
    >
    > }
    >
    > v = GetCookieOpenClose('l');
    >
    > return true;
    > }


    Now that you have posted which methods you call to set and retrieve cookie
    data, it is time that you post their code (because they are not built-ins),
    and say what exactly does not work in what way.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Mar 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben
    Replies:
    3
    Views:
    5,856
    Steven Cheng[MSFT]
    Jun 3, 2004
  2. Replies:
    0
    Views:
    590
  3. Peter Bailey
    Replies:
    5
    Views:
    106
    Peter Bailey
    Jan 16, 2007
  4. Timur Tabi
    Replies:
    1
    Views:
    126
    Timur Tabi
    May 14, 2004
  5. Replies:
    2
    Views:
    337
    Tintin
    Mar 2, 2006
Loading...

Share This Page