...

View Full Version : Cookies



pinkotoad
08-26-2002, 11:02 AM
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:


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:


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:


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

jalarie
08-26-2002, 04:53 PM
:D 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/

pinkotoad
08-27-2002, 04:00 AM
Hmmm...alright, I have no idea what any of that means...

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum