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,coo kieValue,cookie Path,cookieExpi res)
{
cookieValue = escape(cookieVa lue);
if (cookieExpires == "")
{
var nowDate = new Date();
nowDate.setMont h(nowDate.getMo nth() + 6);
cookieExpires = nowDate.toGMTSt ring();
}
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,coo kieValue,cookie Path,cookieExpi res)
{
cookieValue = escape(cookieVa lue);
if (cookieExpires == "")
{
var nowDate = new Date();
nowDate.setMont h(nowDate.getMo nth() + 6);
cookieExpires = nowDate.toGMTSt ring();
}
if (cookiePath != "")
{
cookiePath = ";Path=" + cookiePath;
}
document.cookie = cookieName + "=" + cookieValue + ";expires=" +
cookieExpires + cookiePath;
alert(document. cookie);
}
Comment