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