PDA

View Full Version : Delete all cookies in basket


beautyfiend
07-04-2009, 11:24 AM
Hello again,
I have created a store with a basket and checkout but I dont have a 'delete' what's in your basket.
I have looked around and can't find anything.

I assume I have to make a delete all cookies function?
Any help would be greatly appreciated!
Thank you.

This is all the JS for my basket page:

<script language=JavaScript>

var cart = document.cookie;

function getCookie(name)
{
var index = cart.indexOf(name + "=");
if (index == -1) return null;
index = cart.indexOf("=", index) + 1;
var endstr = cart.indexOf(";", index);
if (endstr == -1) endstr = cart.length;
return unescape(cart.substring(index, endstr));
}

var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days

function setCookie(name, value)
{
if (value != null && value != "")
document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
cart = document.cookie;
}

var kill = getCookie("kill") || 0;
var lost = getCookie("lost") || 0;
var call = getCookie("call") || 0;
var et = getCookie("et") || 0;
var casa = getCookie("casa") || 0;
var blood = getCookie("blood") || 0;
var david = getCookie("david") || 0;
var bob = getCookie("bob") || 0;
var beatles = getCookie("beatles") || 0;

var total = 25 * kill + 8* lost + 28 * call + 9 * et + 5 * casa + 11 * blood + 7 * david + 4 * bob + 13 * beatles;

function getValues()
{
with (document.submitForm) {
kill.value = kill;
lost.value = lost;
call.value = call;
et.value = et;
casa.value = casa;
blood.value = blood;
david.value = david;
bob.value = bob;
beatles.value = beatles;
total.value = total;
}
}
</script>

yell0wdart
07-04-2009, 04:53 PM
You can't directly delete a cookie with JavaScript. The only thing you can do is to set its expire time. Have a look at this article:

http://www.elated.com/articles/javascript-and-cookies/

Also, you may want to think twice about putting this sort of shopping card logic on the client. JavaScript is great because it's fast and allows you to leverage the client's computing power (instead of posting back to the server), but it is not secure by any means.

beautyfiend
07-06-2009, 12:56 PM
You can't directly delete a cookie with JavaScript. The only thing you can do is to set its expire time. Have a look at this article:

http://www.elated.com/articles/javascript-and-cookies/

Also, you may want to think twice about putting this sort of shopping card logic on the client. JavaScript is great because it's fast and allows you to leverage the client's computing power (instead of posting back to the server), but it is not secure by any means.

Ok, thanks for the article.
The site I'm making is for a course, I wouldn't use this kind of payment on a live site.
Thanks for your help.

yell0wdart
07-06-2009, 04:06 PM
Ah, that makes more sense.

You're very welcome. :)

beautyfiend
07-07-2009, 04:59 PM
Ah, that makes more sense.

You're very welcome. :)

That's why I'm so crap at JS! :p