C
Creegan
Below I have a snippet of code for creating a cookie, but am having a
problem assigning data to it. I pass in values to the function which I
know are valid, then I assign this info to the cookie using
document.cookie. But when I try to view the cookie using the alert
function, the cookie is empty. Any ideas why this might be the case?
function setCookieValue
(cookieName,cookieValue,cookiePath,cookieExpires)
{
cookieValue = escape(cookieValue);
if (cookieExpires == "")
{
var nowDate = new Date();
nowDate.setMonth(nowDate.getMonth() + 6);
cookieExpires = nowDate.toGMTString();
}
if (cookiePath != "")
{
cookiePath = ";Path=" + cookiePath;
}
document.cookie = cookieName + "=" + cookieValue + ";expires=" +
cookieExpires + cookiePath;
alert(document.cookie);
}
problem assigning data to it. I pass in values to the function which I
know are valid, then I assign this info to the cookie using
document.cookie. But when I try to view the cookie using the alert
function, the cookie is empty. Any ideas why this might be the case?
function setCookieValue
(cookieName,cookieValue,cookiePath,cookieExpires)
{
cookieValue = escape(cookieValue);
if (cookieExpires == "")
{
var nowDate = new Date();
nowDate.setMonth(nowDate.getMonth() + 6);
cookieExpires = nowDate.toGMTString();
}
if (cookiePath != "")
{
cookiePath = ";Path=" + cookiePath;
}
document.cookie = cookieName + "=" + cookieValue + ";expires=" +
cookieExpires + cookiePath;
alert(document.cookie);
}