setting a cookie - should be easy.

A

anathema

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:

http://www.exit404.com/2005/57/unobtrusive-persistant-scriptaculous-effects

here is my rule

'a.tools' : function(el){
el.onclick = function(){
if (Element.hasClassName('tool-box', 'invisible')) {
new Effect.BlindDown('tool-box');
Element.removeClassName('tool-box', 'invisible');
setCookie(this.parentNode.id, '', 365);
} else {
new Effect.BlindUp('tool-box');
Element.addClassName('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.
 
G

Gary Hasler

anathema said:
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:

http://www.exit404.com/2005/57/unobtrusive-persistant-scriptaculous-effects

here is my rule

'a.tools' : function(el){
el.onclick = function(){
if (Element.hasClassName('tool-box', 'invisible')) {
new Effect.BlindDown('tool-box');
Element.removeClassName('tool-box', 'invisible');
setCookie(this.parentNode.id, '', 365);
} else {
new Effect.BlindUp('tool-box');
Element.addClassName('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.
 
A

anathema

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top