As part of a recent project I'm attempting to reengineer the script below
for netscape navigator. It is a shopping cart that adds each item from the
products page to the cart. My problem is it adds each item individually to
the cart.

What I 'm attempting to achieve is to add items that are the same to the
cart that increments the quantiy by 1 rather than creating a new entry in
the cart which the additem function currently does.

Would appreciate any help on this. I am relatively new to JS and have been
pulling out what little hair I have left in frustration

Thanks


<SCRIPT language=JavaScript>

var items = new Array(8);
var numitems = 0;

function Item(d,c,q) {
this.desc = d;
this.price = c;
this.quantity = q;

}

function additem(desc,price,quantity) {
items[++numitems] = new Item(desc,price,quantity);
displaycart();
}



function hat() { //added function
with(document.hatcart){
if (dstalkers.selectedIndex == 1)
{
additem('Hat Blk Med', 14.95, 1);
return false;
}
if (dstalkers.selectedIndex == 2)
{
additem('Hat Blk Lrg',14.95, 1);
return false;
}
if (dstalkers.selectedIndex == 3)
{
additem('Hat Gry Med',14.95, 1);
return false;
}
if (dstalkers.selectedIndex == 4)
{
additem('Hat Gry Lrg',14.95, 1);
return false;
}
}
return true;
}

function displaycart() {
var cartpic = 'images/cart.jpg';
var totalcost=0;
with (parent.cart.document) {
open();
write('<div align="center">')
write("<HTML><BODY topmargin=0>");
write('<img height="105" width="300" src="' + cartpic + '">');
write("<BR>")
if (numitems==0) {
write("No items ordered.");
close();
return;
}
write('<div align="center">')
write("<TABLE BORDER=1><FORM NAME='form1'>");
for(i=1;i<=numitems;i++) {
write("<TR><TD>");
write("<INPUT NAME='qty' TYPE='TEXT' SIZE=2 VALUE=");
write(items[i].quantity + ">");
write("<TD>" + items[i].desc);
write("<TD>" + items[i].price);
write("<TD>" + (items[i].price * items[i].quantity));
write("</TR>\n");
totalcost += (items[i].price * items[i].quantity);
}
totalcost = Math.floor(totalcost*100) /100;
write("<TR><TD COLSPAN=3><B>Total Cost:</B>");
write("<TD>" + totalcost);
write("</TABLE>");
write("<INPUT TYPE=BUTTON VALUE='Update'");
write("onClick='parent.products.updatecart();'>");
write("<INPUT TYPE=BUTTON VALUE='Complete Order'");
write("onClick='parent.products.complete();'>");
write("<BR>");
write("<INPUT TYPE=BUTTON VALUE='Remove Item'");
write("onClick='parent.products.remitem();'>");
write("</FORM></HTML>");
close();
}
}


function updatecart() {
for (i=1; i<=numitems;i++) {
if (numitems == 1)
items[i].quantity = parent.cart.document.form1.qty.value;
else items[i].quantity = parent.cart.document.form1.qty[i-1].value;
}
displaycart();
}

function complete() {
OrdWin=window.open('cart_complete.html','OrdWin');
}
</SCRIPT>