I have made a small shopping cart in html with javascript. You can put items in with the use of cookies. The problem is the delete button for a row in the shopping cart.
function cartShow(){
intTotalItems = 0;
intTotalItems = readCookie("totalItems");
tabelrow = "";
for (i = 1; i <= intTotalItems; i++){
item = "item" + i;
del = '<a href=""><img src="img/delete.png" onclick="delete1Cookie();" /> </a>';
thisCookie = "";
thisCookie = readCookie(item);
fields = new Array();
fields = thisCookie.split("|");
tabelrow += "<tr>"
+ "<td>" + fields[0] + "</td>"
+ "<td>" + fields[1] + "</td>"
+ "<td>" + fields[2] + "</td>"
+ "<td>" + fields[3] + "</td>"
+ "<td>" + fields[4] + "</td>"
+ "<td>" + fields[5] + "</td>"
+ "<td>" + fields[4] * fields[5] + "</td>"
+ "<td>" + del + "</td>"
+ "</tr>";
}
document.write(tabelrow); }
function delete1Cookie(){
document.cookie = "item1=; 'empty'; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/";}
When i use my function readCookie(item1); i have no problem. it shows the row of the product i want to delete.
But when i want to delete just one cookie my whole shopping cart turns empty.
My code is set to just one cookie for one line "item1" because i think i tried everything, so i would first like to see it work with just one specific row.
I already used the code from: https://stackoverflow.com/a/20156194/4912774 It deleted all my cookies:"item1 item2 etc".
Sorry for any mistakes this is my first post and english is not my native language