Ask a Question related to Macromedia Dynamic HTML, Design and Development.
-
Col #1
javascript shopping cart
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>
Col Guest
-
Like a Shopping Cart but -NOT- a Shopping Cart
Have you ever seen www.apple.com/store? And if you noticed when you choose G5 for example... you select the kind of MAC and then you can customize... -
Shopping cart help
Hi, I need to create a shopping cart style website. Are there any good tutorials or 'shareware' stuff out there that I can look at? I want to do... -
Php Shopping Cart
If anybody can help that would be great. ok here's my problem, i have a PHP shopping cart that i have built in dreamweaver mx 2004 . i have a... -
shopping cart shopping
Im looking to buy some ecommerce software to hook up to an HTML site. The company will have around 350 products or so to start out, and will be... -
JS shopping cart
peterct07@yahoo.com (Peter Cartwright) wrote in message news:<b6141bd7.0307171525.1c322082@posting.google.com>... Oops wrong forum



Reply With Quote

