/    Sign up×
Community /Pin to ProfileBookmark

Cookie reading problem

I’ll try to explain my problem as clearly as possible. My script is not reading the session cookie I’m setting. Its regarding two subsections in my left handside navigation that are expandable/collapsable. They should both be collapsed when first loaded.

[url]http://www.alhuda.org.uk/runescape/index2.php[/url]

Initially, both the (+) and (-) versions of the subsection headings appear. Toggle them both so that only one appears as intended. My script correctly writes a cookie with two values (either 0 or 1 each) to indicate whether each subsection should be collapsed or expanded. However the cookie is not read at all. Here is the Javascript:

[CODE]<script language=”JavaScript” type=”text/javascript”>
<!–

function getcookie2(cookiename) {
var cookiestring=””+document.cookie;
var index1=cookiestring.indexOf(cookiename);
if (index1==-1 || cookiename==””) return “”;
var index2=cookiestring.indexOf(‘;’,index1);
if (index2==-1) index2=cookiestring.length;
return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function setcookie(name,value){
cookiestring=name+”=”+escape(value)+”;PATH=/”;
document.cookie=cookiestring;
}

var cookieArray;
var tempString;
if(!(tempString = getcookie2(“menuCookie”))){
setcookie(‘menuCookie’, ‘0 0’);
cookieArray = [0, 0];
} else {
cookieArray = tempString.split(” “);
}

var menuNames = [“skillguides”, “otherguides”];
var plusNames = [“plusskillguides”, “plusotherguides”];

function toggleMenu(menuID) {

var toggleState = cookieArray[menuID];
var theMenuName = menuNames[menuID];
var thePlusName = plusNames[menuID];

if (toggleState == 0) {
document.getElementById(theMenuName).style.display = “block”;
document.getElementById(thePlusName).style.display = “none”;
cookieArray[menuID] = 1;
} else {
document.getElementById(theMenuName).style.display = “none”;
document.getElementById(thePlusName).style.display = “block”;
cookieArray[menuID] = 0;
}
var theString = cookieArray[0] + ” ” + cookieArray[1];
setcookie(‘menuCookie’, theString);
}

//–>
</script>[/CODE]

Although I’ve tried searching, I think I couldn’t adapt what I’ve found to reading the correct value of the cookie for each subsection. Any help would be very much appreciated by this Javascript illiterate coder.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Ali_JauthorJul 23.2005 — Bump from page 2
×

Success!

Help @Ali_J spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...