What I am trying to achieve is this: I want button where I can add my item to the shopping cart e.g AddToCart() so I can add my items with the number of quantities that the person will want. To do this I need global arrays like sum, quanitity and name. Except the way I have done it does not have this and I'm not sure how implement this.
I then need a ViewShoppingCart() which will make a loop through the arrays and display it in a table with the total sum. What I have done is a bit similar but my knowledge and experience was not enough to accomplish the above problem. I hope this makes more sense.
(I have a feeling the code I have so far is wrong)
var productname = new array();
var productprice = new array();
var productquantity = new array();
var name = 'title'+i;
var price = 'price'+i;
var quantity = 'qty'+i;
productname[i] = document.getElementById(name).innerHTML;
productprice[i] = document.getElementById(price).innerHTML;
var selectfield = document.getElementById(quantity).
productquantity[i] = selectfield.options[selectfield.selectedIndex].text;
I know I need to quantity into integer, price into float and do the calculations you plan to do. So total price would be productprice + productprice + productprice. But I am now stuck and don't know how to continue. If someone could guide me or give me some hints that would be very helpful.
Ah Thankyou very much, it works now
I have something I found and I'm trying to add it but I don't know what going on here.
var total = 0;
var i = 0;
write("<H2>Thank you for your order</H2>");
write("<TABLE BORDER=1 CELLPADDING=3 CELLSPACING=1 WIDTH=500>");
for (i in cart)
total = total + cart[i].price;
if (cart[i].itemcnt != null);
write("<TR><TD>Total = </TD><TD ALIGN=RIGHT>$" + total + "</TD>");
And then I guess I am going to need something like
hmmm I tried that code but when I click add to cart nothing happens? I've linked it.
EDIT: its working now thanks , btw is there a way I can add a view function cart? so I can view the the information and total in a table on the same page?
Last edited by shadowplayer; 05-08-2010 at 06:20 AM.