Hi there,
I am writing a shopping cart application, and I need to know how to clear the cookie, and hence cart. I realise the following code may be a bit hard to follow, but any help would be appreciated. I got the following code on the web. Here is the cookie code on the product page (Product is called 'lespaul, cookie is called 'guitar':
var guitar = document.cookie;
function getCookie(name) { // use: getCookie("name"
;
var index = guitar.indexOf(name + "="
;
if (index == -1) return null;
index = guitar.indexOf("=", index) + 1;
var endstr = guitar.indexOf(";", index);
if (endstr == -1) endstr = guitar.length;
return unescape(guitar.substring(index, endstr));
}
var today = new Date();
function setCookie(name, value) { // use: setCookie("name", value);
if (value != null && value != ""
document.cookie=name + "=" + escape(value) + ";
guitar = document.cookie; // update guitar
}
// End of cookie code
function getValues() {
with (document.orderForm) {
lespaul.value = getCookie("lespaul"
|| 0;
}
}
And this is on the cart page:
var guitar = document.cookie;
function getCookie(name) { // use: getCookie("name"
;
var index = guitar.indexOf(name + "="
;
if (index == -1) return null;
index = guitar.indexOf("=", index) + 1;
var endstr = guitar.indexOf(";", index);
if (endstr == -1) endstr = guitar.length;
return unescape(guitar.substring(index, endstr));
}
var today = new Date();
function setCookie(name, value) { // use: setCookie("name", value);
if (value != null && value != ""
document.cookie=name + "=" + escape(value) + ";
guitar = document.cookie; // update guitar
}
// End of cookie code
var lespaul = getCookie("lespaul"
|| 0;
var total = 2500 * lespaul;
function getValues() { // fill in hidden fields
with (document.submitForm) {
lespaul.value = lespaul;
total.value = total;
}
}
var start = "<TR align='center'>\n<TH align='left'>";
var mid = "</TH>\n<TD>";
var end = "</TD>\n</TR>\n";
if (lespaul) document.write(start + "Gibson Les Paul Classic" + mid + lespaul + mid + "£2500" + mid + "£" + (lespaul * 2500) + ".00" + end);
document.write("<TR><TH colspan='3' align='right'>Total:</TH><TH>£" + total + ".00</TH></TR>"
;
This code is adding to the cart perfectly. All I need is the code to clear the items from the cookie, and hence the cart. Can anyone help???
Thanks in advance,
Conor
I am writing a shopping cart application, and I need to know how to clear the cookie, and hence cart. I realise the following code may be a bit hard to follow, but any help would be appreciated. I got the following code on the web. Here is the cookie code on the product page (Product is called 'lespaul, cookie is called 'guitar':
var guitar = document.cookie;
function getCookie(name) { // use: getCookie("name"
var index = guitar.indexOf(name + "="
if (index == -1) return null;
index = guitar.indexOf("=", index) + 1;
var endstr = guitar.indexOf(";", index);
if (endstr == -1) endstr = guitar.length;
return unescape(guitar.substring(index, endstr));
}
var today = new Date();
function setCookie(name, value) { // use: setCookie("name", value);
if (value != null && value != ""
document.cookie=name + "=" + escape(value) + ";
guitar = document.cookie; // update guitar
}
// End of cookie code
function getValues() {
with (document.orderForm) {
lespaul.value = getCookie("lespaul"
}
}
And this is on the cart page:
var guitar = document.cookie;
function getCookie(name) { // use: getCookie("name"
var index = guitar.indexOf(name + "="
if (index == -1) return null;
index = guitar.indexOf("=", index) + 1;
var endstr = guitar.indexOf(";", index);
if (endstr == -1) endstr = guitar.length;
return unescape(guitar.substring(index, endstr));
}
var today = new Date();
function setCookie(name, value) { // use: setCookie("name", value);
if (value != null && value != ""
document.cookie=name + "=" + escape(value) + ";
guitar = document.cookie; // update guitar
}
// End of cookie code
var lespaul = getCookie("lespaul"
var total = 2500 * lespaul;
function getValues() { // fill in hidden fields
with (document.submitForm) {
lespaul.value = lespaul;
total.value = total;
}
}
var start = "<TR align='center'>\n<TH align='left'>";
var mid = "</TH>\n<TD>";
var end = "</TD>\n</TR>\n";
if (lespaul) document.write(start + "Gibson Les Paul Classic" + mid + lespaul + mid + "£2500" + mid + "£" + (lespaul * 2500) + ".00" + end);
document.write("<TR><TH colspan='3' align='right'>Total:</TH><TH>£" + total + ".00</TH></TR>"
This code is adding to the cart perfectly. All I need is the code to clear the items from the cookie, and hence the cart. Can anyone help???
Thanks in advance,
Conor