Help with shopping cart in javascript

Posted by user228390 on Stack Overflow See other posts from Stack Overflow or by user228390
Published on 2010-05-03T20:03:10Z Indexed on 2010/05/03 20:08 UTC
Read the original article Hit count: 204

Hey guys, I'm having problems with my shopping cart. What I am trying to do is make a function that will add an item the cart and then and function that will view the cart and show the details. But what I have got so far does not do that, it just simply adds and goes straight to view cart. Also I wanted to store the name of each items in different global arrays (name, price and sum) but I can't get it work that way. Can any help me overcome this problem?

Edit: I've tried to get it to work by adding some more items and attaching it to another html page, but now the code does not seem to work at all , before it showed the price and total and now I get nothing .

javascript code

  function round_total (c) {
         var pennies = c * 100;
         pennies = Math.round(pennies);
         var strPennies = "" + pennies;
         var len = strPennies.length;
         return parseFloat(strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len));
 }
 // End of round_total function.

 /* Start of generate_page function. */
 function generate_page (form) {
         tax = 0.08;
         delivery_p = 2.99;
         var odate = new Date();
         var qty = form.quantity.value;
         var product_v = new String(form.product.value);
         var total_price = product_v.substr(product_v.indexOf("$") + 1, product_v.length - product_v.indexOf("$"));
         var price_without_tax = round_total(qty * total_price);
         var ttax = round_total(price_without_tax * tax);
         var delivery = round_total(qty * delivery_p);
         var total_p = round_total(price_without_tax + ttax + delivery);
         document.writeln("Quantity: " + qty + "<br>");
         document.writeln("Price: $" + total_price + "<br>");
         document.writeln("Delivery: $" + delivery + "<br>");
         document.writeln("Total: $" + total_p + "<br>");
         document.writeln("Order placed on: " + odate.toGMTString());
 }

function calculate() { round_total (c)(); generate_page (form)(); }

HTML code: Shopping cart

Welcome, Guest Login Sign Up

Stay Updated: Subscribe via RSS Email Updates

<div id="header">

<div id="branding" class="container">
<h1>The Finest Toy<br /> Store Online</h1>
<p class="desc">If you're looking for a toy shop then look no further.<br/> Go on, treat the kids with our 
                huge selection of<br/>online toy shops selling 
                toys for all ages.</p>
            </div><!-- end branding -->

            <div id="navigation">
                <ul id="menu" class="container">
                    <li><a href="#">HOME</a></li>
                    <li><a href="#">ABOUT</a></li>
                    <li><a href="#">Online Store</a></li>
                    <li><a href="#">CONTACT</a></li>
                </ul>
            </div><!-- end navigation -->

        </div><!-- end header -->
Shopping Cart

Nintendo DS Xbox

Product: Console £149.99 Console + Games £169.99

Quantity:

Product: Console £149.99 Console + Games £169.99

Quantity:

 

  Playstation 3 Wii

Product: Console £149.99 Console + Games £169.99

Quantity:  

Product: Console £149.99 Console + Games £169.99

Quantity:  

 

 

 


 <input type="submit" value="Add to cart" name="submit" onClick="cart()";/><input

, type="reset" value="Reset" name="reset">

Copyright © 2010 shopping cart. Content and Header © |Back to top




Do I need to show my CSS as well? (Sorry about the coding its not working properly for me, its not showing up the way it should be)

© Stack Overflow or respective owner

Related posts about homework

Related posts about JavaScript