tiki Posted June 13, 2006 Share Posted June 13, 2006 Im trying to create a javascript open and close feature (you know expand or collapse). That is easily done with a simple function, but I want this to also remember if its open or closed so the next time they visit its how they wanted it, open or closed.So far this is what I have and its not working, any help would be greatly appreciated.[code]// COLLAPSE CONTENT SCRIPT, BY RYAN BARR and haxed by Miles Johnsonfunction set(name, value, expires) { if (!expires) { expires = new Date(); } document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";}function fetch(name) { cookie_name = name + "="; cookie_length = document.cookie.length; cookie_begin = 0; while (cookie_begin < cookie_length) { value_begin = cookie_begin + cookie_name.length; if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) { var value_end = document.cookie.indexOf (";", value_begin); if (value_end == -1) { value_end = cookie_length; } return unescape(document.cookie.substring(value_begin, value_end)); } cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1; if (cookie_begin == 0) { break; } } return null;}function save(id, addcollapsed) { var collapsed = fetch("admin_collapse"); var tmp = new Array(); if (collapsed != null) { collapsed = collapsed.split("\n"); for (i in collapsed) { if (collapsed[i] != id && collapsed[i] != "") { tmp[tmp.length] = collapsed[i]; } } } if (addcollapsed) { tmp[tmp.length] = id; } expires = new Date(); expires.setTime(expires.getTime() + (1000 * 86400 * 365)); set("admin_collapse", tmp.join("\n"), expires);}function toggle(id){ var div = document.getElementById(id); if(div.style.display == 'none') { save(id, false); div.style.display = 'block'; } else{ save(id, true); div.style.display = 'none'; }}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.