Code:
document.write("cookie we have is " + document.cookie + "<br>");
var allcookies = document.cookie;
var cookiearray = allcookies.split(';');
for(var i=0; i<cookiearray.length; i++){ // this is looping through all cookies
var Cookiename = cookiearray[i].split('=')[0]; // ..so these will end up storing the name and value
var Cookievalue = cookiearray[i].split('=')[1]; // ..of whatever is the last cookie
alert("Key is : " +Cookiename + " and Value is : " + Cookievalue);
}
DelCookie(Cookiename); // so this will delete the LAST cookie
UpdateCookie(Cookievalue);
function DelCookie(Cookiename)
{
document.cookie = Cookiename + "=" + " " + ";expires=Fri, 01-Jan-2010 00:00:01 UTC" ;
document.write("cookie we have is " + document.cookie + "<br>");
}
function UpdateCookie(Cookievalue)
{
var loginid = 100020002;
var newCookievalue = Cookievalue.concat(loginid);
document.cookie=Cookiename + "=" + newCookievalue;
document.write("cookie we have is " + document.cookie + "<br>");
alert ("New Value is " +newCookievalue );
}
Also, as mentioned in other posts, you should use a version of a deleteCookie function that allows the specifying of the path, usually as "/". My function would be used like this:
Code:
deleteCookie(someName, '/');
You should wrap your code in CODE tags by clicking the hash (#) key when creating your posts.