setting a cookie - should be easy.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • anathema

    #1

    setting a cookie - should be easy.

    this is not specifically behaviour related, but i thought i would risk
    asking anyway.

    i am working on a script that triggers a blind down or blind up effect
    by clicking on a particular link. it then remembers the status of that
    choice by setting a cookie.

    the technique was taken from here:



    here is my rule

    'a.tools' : function(el){
    el.onclick = function(){
    if (Element.hasCla ssName('tool-box', 'invisible')) {
    new Effect.BlindDow n('tool-box');
    Element.removeC lassName('tool-box', 'invisible');
    setCookie(this. parentNode.id, '', 365);
    } else {
    new Effect.BlindUp( 'tool-box');
    Element.addClas sName('tool-box', 'invisible');
    setCookie(this. parentNode.id, 'invisible', 365);
    }
    }
    }



    the problem is this line

    setCookie(this. parentNode.id, '', 365);

    that was taken directly from the artilcle but does not apply to my
    situation. in the article he is applying the effects to the same
    element that is clicked on, so 'this' is used in the function, where as
    i am using 'tool-box', which is the id of the div that is getting
    triggered.

    so when i get the setCookie part, i need to rewrite it so that it
    associates itself with the div 'tool-box instead of 'this'. basically i
    just do not know the proper syntax. i tried...

    setCookie('tool-box', 'invisible', 365);

    but that did not seem to work for me.

    any thoughts?

    p.s. i did not include the cookie stuff because i do not think it is
    needed, but if you think it would be helpful, i can included or you can
    find it in the article.

  • Gary Hasler

    #2
    Re: setting a cookie - should be easy.

    anathema wrote:
    >
    this is not specifically behaviour related, but i thought i would risk
    asking anyway.
    >
    i am working on a script that triggers a blind down or blind up effect
    by clicking on a particular link. it then remembers the status of that
    choice by setting a cookie.
    >
    the technique was taken from here:
    >

    >
    here is my rule
    >
    'a.tools' : function(el){
    el.onclick = function(){
    if (Element.hasCla ssName('tool-box', 'invisible')) {
    new Effect.BlindDow n('tool-box');
    Element.removeC lassName('tool-box', 'invisible');
    setCookie(this. parentNode.id, '', 365);
    } else {
    new Effect.BlindUp( 'tool-box');
    Element.addClas sName('tool-box', 'invisible');
    setCookie(this. parentNode.id, 'invisible', 365);
    }
    }
    }
    >
    the problem is this line
    >
    setCookie(this. parentNode.id, '', 365);
    >
    that was taken directly from the artilcle but does not apply to my
    situation. in the article he is applying the effects to the same
    element that is clicked on, so 'this' is used in the function, where as
    i am using 'tool-box', which is the id of the div that is getting
    triggered.
    >
    so when i get the setCookie part, i need to rewrite it so that it
    associates itself with the div 'tool-box instead of 'this'. basically i
    just do not know the proper syntax. i tried...
    >
    setCookie('tool-box', 'invisible', 365);
    >
    but that did not seem to work for me.
    >
    any thoughts?
    >
    p.s. i did not include the cookie stuff because i do not think it is
    needed, but if you think it would be helpful, i can included or you can
    find it in the article.
    (I don't have the time to examine it closely, but I think this is
    right...someone please correct me if I'm mistaken):

    The reason the script uses "this" is because it is attaching a behaviour
    to a class; that is, all elements belonging to that class will inherit
    the behaviour, which will affect the element itself when clicked.
    Unless you want all of the links in a class to have exactly the same
    effect (which could be to roll up some other element named "toolbox"),
    you need to put a different onclick event in each link, which calls a
    function with the appropriate name given as a parameter.

    Comment

    • anathema

      #3
      Re: setting a cookie - should be easy.

      I know why it is using 'this' for the original script. It is setting
      the cookie for a.tools. I want to set it for tool-box, i just do not
      know the syntax.

      On Jan 22, 5:27 pm, Gary Hasler <garyhas...@the logconnection.c om>
      wrote:
      anathema wrote:
      >
      this is not specifically behaviour related, but i thought i would risk
      asking anyway.
      >
      i am working on a script that triggers a blind down or blind up effect
      by clicking on a particular link. it then remembers the status of that
      choice by setting a cookie.
      >
      the technique was taken from here:
      >>
      here is my rule
      >
      'a.tools' : function(el){
      el.onclick = function(){
      if (Element.hasCla ssName('tool-box', 'invisible')) {
      new Effect.BlindDow n('tool-box');
      Element.removeC lassName('tool-box', 'invisible');
      setCookie(this. parentNode.id, '', 365);
      } else {
      new Effect.BlindUp( 'tool-box');
      Element.addClas sName('tool-box', 'invisible');
      setCookie(this. parentNode.id, 'invisible', 365);
      }
      }
      }
      >
      the problem is this line
      >
      setCookie(this. parentNode.id, '', 365);
      >
      that was taken directly from the artilcle but does not apply to my
      situation. in the article he is applying the effects to the same
      element that is clicked on, so 'this' is used in the function, where as
      i am using 'tool-box', which is the id of the div that is getting
      triggered.
      >
      so when i get the setCookie part, i need to rewrite it so that it
      associates itself with the div 'tool-box instead of 'this'. basically i
      just do not know the proper syntax. i tried...
      >
      setCookie('tool-box', 'invisible', 365);
      >
      but that did not seem to work for me.
      >
      any thoughts?
      >
      p.s. i did not include the cookie stuff because i do not think it is
      needed, but if you think it would be helpful, i can included or you can
      find it in the article.(I don't have the time to examine it closely, but I think this is
      right...someone please correct me if I'm mistaken):
      >
      The reason the script uses "this" is because it is attaching a behaviour
      to a class; that is, all elements belonging to that class will inherit
      the behaviour, which will affect the element itself when clicked.
      Unless you want all of the links in a class to have exactly the same
      effect (which could be to roll up some other element named "toolbox"),
      you need to put a different onclick event in each link, which calls a
      function with the appropriate name given as a parameter.

      Comment

      Working...