M
MikeS
I'm trying to add items to a shopping cart, if the item is already added I
want to just increase the quantity by 1 instead for adding a new Item, I've
got it nearly working for the first item ...but after that it just keeps
adding a new Item. What am I doing wrong - I've been racking my brains
trying to figure this out all day.
function additem(desc,price,quantity) {
if (numitems>=1){
for(i=1;i<=numitems;i++) {
if(cart.desc == desc){
++cart.quantity
}
else{
cart[++numitems] = new Item(desc,price,quantity);
}
displaycart();
}
}else{
cart[++numitems] = new Item(desc,price,quantity);
displaycart();
}
}
Thanks
Mike
want to just increase the quantity by 1 instead for adding a new Item, I've
got it nearly working for the first item ...but after that it just keeps
adding a new Item. What am I doing wrong - I've been racking my brains
trying to figure this out all day.
function additem(desc,price,quantity) {
if (numitems>=1){
for(i=1;i<=numitems;i++) {
if(cart.desc == desc){
++cart.quantity
}
else{
cart[++numitems] = new Item(desc,price,quantity);
}
displaycart();
}
}else{
cart[++numitems] = new Item(desc,price,quantity);
displaycart();
}
}
Thanks
Mike