Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ajax Programming

Writing a cookie syntax

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.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 article 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

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.

if toolbox is the name of thediv and it is not dynamic, why don't you jut
use the string toolbox?


On 1/22/07, anathema <spamfreeunive@gmail.com> wrote:

Can you show me how you would write it?

Like I said, I tried this -

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

But that did not work for me.


I think i figured out that my syntax was correct so the problem lies
somewhere else. Here is the bigger picture.

This is the desired outcome - a user clicks on a#tools-link. This shows
/ hides the div #tool-box and a cookie is set to remember it's status
so that when the user goes to another page the #tool-box retains their

The show / hide part is fine. It is the cookie stuff I can not get

The function hideBoxes is what is messed up. It is supposed to look at
the cookie and if it is set to invisible, then it should set the class
of #tool-box to 'invisible'

The function is overkill for what I am doing. It was originally
designed to keep track of multiple boxes, but I am only keeping track
of 1 for now. I do not think I need any of the var kids stuff. So How
can i rewrite that function to do what I need?

Here is the code.

// These are behaviour.js rules

var myrules = {
        'a#tools-link' : function(el){
                        el.onclick = function(){
                                if (Element.hasClassName('tool-box', 'invisible')) {
                                        new Effect.BlindDown('tool-box');
                                        Element.removeClassName('tool-box', 'invisible');
                                        setCookie('tool-box', '', 365);
                                } else {
                                        new Effect.BlindUp('tool-box');
                                        Element.addClassName('tool-box', 'invisible');
                                        setCookie('tool-box', 'invisible', 365);
                                return false;


// Cookie stuff

        function hideBoxes() {

                // Id names of all the "boxes"
                boxIds = $("tool-box");

                for (i = 0; i < boxIds.length; i++) {
                        if (boxIds[i]) {
                                cookieValue = readCookie(boxIds[i].id);
                                if (cookieValue == 'invisible') {
                                        var div = boxIds[i].getElementsByTagName('div');
                                        Element.addClassName(div[0], 'invisible');
                                        var kids = boxIds[i].childNodes;
                                        for (j = 1; j < kids.length; j++) {
                                                if (kids[j].id) {

        function setCookie(name,value,days) {
         if (days) {
                 var date = new Date();
                 var expires = ";expires="+date.toGMTString();
         } else {
                 expires = "";
         document.cookie = name+"="+value+expires+";path=/";

        function readCookie(name) {
         var needle = name + "=";
         var cookieArray = document.cookie.split(';');
         for(var i=0;i < cookieArray.length;i++) {
                 var pair = cookieArray[i];
                 while (pair.charAt(0)==' ') {
                         pair = pair.substring(1, pair.length);
                 if (pair.indexOf(needle) == 0) {
                         return pair.substring(needle.length, pair.length);
         return null;

        // Register the behaviour rules and load a few functions onload.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc