Note that there are some explanatory texts on larger screens.

plurals
  1. POtotal price according to quantity written for multiple items
    primarykey
    data
    text
    <p>hello i am making a shopping cart system but i am stuck in the calculations of total products with number of quantities i want that a user selects a price from drop down and then on entering the quantity it updates the total instant and same goes for the other items . i made a js fiddle for the structure can anyone help me achieve this via simple javascript ? </p> <p><a href="http://jsfiddle.net/nVCY4/25/" rel="nofollow">http://jsfiddle.net/nVCY4/25/</a></p> <p>the drop down structure is like </p> <pre><code>&lt;select id="TIPR1" class="table-select" title="Please select"&gt; &lt;option value="31"&gt;Field Box $31&lt;/option&gt; &lt;option value="29"&gt;Lodge Box $29&lt;/option&gt; &lt;option value="19"&gt;Bleachers $19&lt;/option&gt; &lt;/select&gt; function CalculateTotal(frm) { var order_total = 0 // Run through all the form fields for (var i=0; i &lt; frm.elements.length; ++i) { // Get the current field form_field = frm.elements[i] // Get the field's name form_name = form_field.name // Is it a "product" field? if (form_name.substring(0,4) == "TIQT") { // If so, extract the price from the name //item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1)) var test = "TIPR1,TIPR2"; //test = test + i; var e = document.getElementById(test); item_price = e.options[e.selectedIndex].value; // Get the quantity item_quantity = parseInt(form_field.value) // Update the order total if (item_quantity &gt;= 0) { order_total += item_quantity * item_price } } } // Display the total rounded to two decimal places document.getElementById("order_total").firstChild.data = "$" + } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload