Hi Andrew,
I am not the same user for whom you provided the solution. I am actually new user, working on cookie value updation.
I basically need to create a unique cookie for users browsing through single computer.
I have created a subdomain of my client server on other linux server and kept my html pages under the cgi-bin folder of apache server
the apache server is running on port 1080. also I have modified my system hostfile (added name of the my subdomain with IP)
this is the URL type I am giving at my browser.
http://subdomain.domainname.com:port...yhtmlpage.html
Now doing so, client server will send cookie with 2 cookies (X=value;Y=value). for making unique cookie I need to update the value of Y cookie with some value
I am reading the cookie via document.cookie. then storing both the values in an array. and later seprating the value and name from name value pair stored in array.
Once this is done, I am deleting the Y cookie by setting the expiry date and then using document.cookie to create a new Y cookie with new value.
Now In doing so when I am printing the old value, deleted value and new value through document.write. everything is happening as intended
but when I checked the cookie stored at location (). firstly it was storing both the values (x and y) When I deleted Y, it was having only X in the file
but when I created Y with new value. it didnt got reflected.
Code snippet is below
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++){
var Cookiename = cookiearray[i].split('=')[0];
var Cookievalue = cookiearray[i].split('=')[1];
alert("Key is : " +Cookiename + " and Value is : " + Cookievalue);
}
DelCookie(Cookiename);
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 );
}