Click to See Complete Forum and Search --> : Problems with cookies and stuff


FeldmanSkitzoid
10-12-2003, 02:33 PM
Hi, I've got a bit of a problem with a script I've been working on. It uses cookies to set a variable, but when I try to get the variable to execute a function, it doesn't do anything.

The page is located here (http://www.theinsaneasylum.com/layout_2003/center/quote.php). You probably want to see what it's doing. Just click the header text. Essentially, I want it to remember if a person had the box "rolled up" or not. I'm modifying someone else's code so it remembers.

Here's the javascript:
<script type="text/javascript">
//Toggle Boxes Script
var toggle_thingy = unescape(document.cookie); //I added this
function toggle( targetId ){
if (document.getElementById){
target = document.getElementById( targetId );
//Unroll
if (target.style.display == "none"){
target.style.display = "";
toggle_thingy = 0; //I added this
document.cookie = escape(toggle_thingy); //I added this
} else {
//Roll
target.style.display = "none";
toggle_thingy = target.style.display; //I added this
document.cookie = escape(toggle_thingy); //I added this
}
}
}
</script>
and directly beneath that:

<script type="text/javascript">
if (toggle_thingy == "none"){
toggle('center_quote');}
</script>
I get the feeling that the problem is in that second line, but I can't figure out what. I have to admit, I'm pretty bad with javascript.

Thanks for any help you can give!

Khalid Ali
10-12-2003, 07:14 PM
when you set a cookie,you will need to set at least these 2 parameters
name=cookieName; expires=Mon, 01-Jan-2004 00:00:00 GMT

FeldmanSkitzoid
10-12-2003, 08:19 PM
Where would I put those? Would it be something along the lines of document.cookie = name(the_cookies_name) and document.cookie = expires(yadda yadda)?

Thanks for the help.

Khalid Ali
10-13-2003, 09:31 AM
the function below will create a cookie with expiration date 1 minute from now...you will need to pass the cdata to thsi function(val parameter)

function createCookie (val) {
var expire = new Date ();
expire.setTime (expire.getTime() + (coockieTimer * 60000)); //1 mins from now!
document.cookie = cookieName+"=" + escape (val) + "; expires=" + expire.toGMTString();
}