[Javascript Error]
Hello, I have a webpage which sets a cookie:
function start() {
var expirydate=new Date();
expirydate.setTime(expirydate.getTime()+(100*60*60*24*100));
setCookie('product',null,expirydate);
window.location="mainpage.html";}
function setCookie(name,value,expires){
document.cookie = name + "=" + value + ((expires==null) ? "" : ";expires=" + expires.toGMTString())}
then another webpage accesses it:
function cart(productName) {
var expirydate=new Date();
expirydate.setTime(expirydate.getTime()+(100*60*60*24*100))
var productnames=getCookie('product')
alert(productnames);
var products=productnames+" "+productName;
setCookie('product',products,expirydate);
alert(products);
window.location = "cart.html";}
and adds (concatenates) the old value of the cookie with a new input by the viewer, and saves it.
This is for the purpose of a cart. Each time the viewer clicks "Add to cart" on the products page, the product name (productName) gets added to the cookie containing all the products the viewer has already added.
However, this doesn't seem to work. The webpage accessing the cookie resets it to null everytime it adds something to the cookie. Therefore, instead of a list of product names, I only get the name of the product the viewer last chose.
Please HELP! It's very very urgent! Thanks in advance.