Danny99999
12-05-2006, 05:38 PM
OMG, I'm tearing my hair out over this problem I'm having.
I have a cookie I am setting in Javascript, BUT it will not set unless I have an alert message somewhere before setting the cookie. I don't understand why. :confused:
here's the function I'm using to set the cookie:
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
var time=exdate.toGMTString()
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+time)+";path=/"
}
The cookie will set if I place an alert anywhere in the setcookie function before the line:
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+time)+";path=/"
It all starts here:
I have an HTML anchor with the attribute onclick='update_state(\"C1\",\"2\")'
Here's the function update_state which calls the setcookie function:
function update_state(panel,state){
var cookie_val = getCookie("me");
var substr=cookie_val.substring(cookie_val.indexOf(panel), cookie_val.indexOf(panel)+5);
var substr2=cookie_val.substring(cookie_val.indexOf(panel), cookie_val.indexOf(panel)+4);
cookie_val=cookie_val.replace(substr, substr2+state);
setCookie("me",cookie_val,364);
}
Please help!!!!!
I have a cookie I am setting in Javascript, BUT it will not set unless I have an alert message somewhere before setting the cookie. I don't understand why. :confused:
here's the function I'm using to set the cookie:
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
var time=exdate.toGMTString()
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+time)+";path=/"
}
The cookie will set if I place an alert anywhere in the setcookie function before the line:
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+time)+";path=/"
It all starts here:
I have an HTML anchor with the attribute onclick='update_state(\"C1\",\"2\")'
Here's the function update_state which calls the setcookie function:
function update_state(panel,state){
var cookie_val = getCookie("me");
var substr=cookie_val.substring(cookie_val.indexOf(panel), cookie_val.indexOf(panel)+5);
var substr2=cookie_val.substring(cookie_val.indexOf(panel), cookie_val.indexOf(panel)+4);
cookie_val=cookie_val.replace(substr, substr2+state);
setCookie("me",cookie_val,364);
}
Please help!!!!!