Object help needed

Giganews Newsgroups
Subject: Object help needed
Posted by:  MikeS (nospam@secure.f9.co.uk)
Date: Wed, 9 Jul 2003

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[i].desc == desc){
  ++cart[i].quantity
  }
  else{
  cart[++numitems] = new Item(desc,price,quantity);
  }
  displaycart();
  }
}else{
cart[++numitems] = new Item(desc,price,quantity);
displaycart();
}
}

Thanks
Mike

Replies