Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing a shopping cart 1

Status
Not open for further replies.

cdumigan

MIS
Feb 5, 2002
16
0
0
IE
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 = &quot;<TR align='center'>\n<TH align='left'>&quot;;
var mid = &quot;</TH>\n<TD>&quot;;
var end = &quot;</TD>\n</TR>\n&quot;;

if (lespaul) document.write(start + &quot;Gibson Les Paul Classic&quot; + mid + lespaul + mid + &quot;£2500&quot; + mid + &quot;£&quot; + (lespaul * 2500) + &quot;.00&quot; + end);
document.write(&quot;<TR><TH colspan='3' align='right'>Total:</TH><TH>£&quot; + total + &quot;.00</TH></TR>&quot;);


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
 
Here's how to do it, sorry i didn't look at your script since you know it you'll now what to do...

Code:
function destroyCookie()
   {
    DeleteCookie (&quot;name&quot;)
    DeleteCookie (&quot;nick&quot;)
    DeleteCookie (&quot;birth_date&quot;)
   }

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + &quot;=&quot; +
      ((path) ? &quot;; path=&quot; + path : &quot;&quot;) +
      ((domain) ? &quot;; domain=&quot; + domain : &quot;&quot;) +
      &quot;; expires=Thu, 01-Jan-70 00:00:01 GMT&quot;;
  }
}
I know it's in two part cause i was using the cookie functions in another page. ;-)
Have Fun...

Sharky99 >:):O>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top