Hi, I have an page with some JS that switches tabs, I want to set a JS cookie so that when the user reloads the page the tab option that had selected starts off open.
Here is the JS code i have
[code=php]
<script type=”text/javascript” charset=”utf-8″>
function swapDivs(id,caller,button,buttonOff) {
document.getElementById(caller).style.display = ”;
document.getElementById(id).style.display = ‘none’;
document.getElementById(button).style.background = ‘#ed7819’;
document.getElementById(buttonOff).style.background = ‘#829189’;
createCookie(‘hideDiv’,caller,’1′);
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = “; expires=”+date.toGMTString();
}
else var expires = “”;
document.cookie = name+”=”+value+expires+”; path=/”;
}
function readCookie(name) {
var nameEQ = name + “=”;
var ca = document.cookie.split(‘;’);
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==’ ‘) c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
</script>
The tab switching works fine, but I cant seam to get the cookie to be remembered. or found.
Here is the section that calls the open tab, and hides the other one.
[code=php]
<script type=”text/javascript” charset=”utf-8″>
var x = readCookie(‘hideDiv’)
if (x) {
createCookie(‘hideDiv’,’orphanDiv’,’1′); // Hide this one be default, if no cookie is set.
}
document.getElementById(readCookie(‘hideDiv’)).style.display = ‘none’;
</script>