Jump to content

Help making an array of this simple shopping cart


Recommended Posts

I made this simple shopping cart where you select quantity from a dropwdown list and these numbers get added and you get a total number for all the products and a total number for the product itself.

But i want it write the quantity with price and the name and write it in a div placed on the site so that it is easy for the user to see that he added a product. I made the calculating part by adding the products one by one, as i did not array them. But for this next part i just didn't find a way that suited my needs. This is just from my test page , so i only have a few values , but in the other page i have over 70 listed just like these:


<div id="radioAlert">

<script type="text/javascript">
function updatesum() {
document.form.sum.value =
(document.form.sum0.value -0) *99 +
(document.form.sum1.value -0) *99 +
(document.form.sum2.value -0) *99;

document.form.smu.value =
(document.form.prod0.value -0)*99  +
(document.form.prod1.value -0) *99 +
(document.form.prod2.value -0) *99 +
(document.form.prod3.value -0) *99 +
(document.form.prod4.value -0) *99;
document.form.totalsum.value =
(document.form.sum.value -0) +
(document.form.smu.value -0); //not a typo i was just lazy with the name


//This one i did not get to work.
var myArray = newArray();

for (var i = 0; i < myArray.length; i++) {
//this part works but i want it to add its value only once and then replace its value if its updated again, if its 0 i want it to be completely removed.
var prod1 = document.form.sum2.value;
var prod2 = document.form.sum1.value;
var radioAlert = document.getElementById("radioAlert");
var radioAlert2 = document.getElementById("radioAlert"); 
if  (document.form.sum2.value>0) {
//document.write("pilotjakke pelsforet small  " +   prod1 + "  stk");
radioAlert.innerHTML += ("pilotjakke pelsforet small  " +   prod1 + "  stk");
alert("pilotjakke pelsforet medium  " +   prod1 + "  stk");
if  (document.form.sum1.value>0) {
//document.write("pilotjakke pelsforet small  " +   prod1 + "  stk");
radioAlert2.innerHTML += ("pilotjakke pelsforet medium  " +   prod2 + "  stk");


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.