Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculating Values loaded in via jquery
    primarykey
    data
    text
    <p>A continuation from a solved case with a new problem. The following code calculates values that are loaded in via ajax from another script. A series of options in another form determine what information is loaded in and therefore what the final calculations are.</p> <p>The problem is that once you have loaded in all the available options you cannot then load them out and the script that adds up all the field totals does in fact fail at this point. So for example if you load in 2 options it will had up the totals. Load in a third and it will add up the total of all 3. Take one option out and the script then fails. I believe it is something to do with the way the script fetches the product ids &mdash; <code>var productIds = {};</code> </p> <p>Any help would be appreciated</p> <p>Here is the code</p> <pre><code>var productIds = {}; function product_totals(id) { productIds[id] = true; // store all id's as the totals are calculated var quantity = $c('product_quantity_' + id).value; var price = $c('product_price_' + id).value; var duration = $c('product_duration_' + id).value; var dives = $c('product_dives_' + id).value; var hire = $c('product_hire_' + id).value; Number($c('product_price_total_' + id).value = price * quantity); Number($c('product_duration_total_' + id).value = duration * quantity); Number($c('product_dives_total_' + id).value = dives * quantity); Number($c('product_hire_total_' + id).value = hire * quantity); function $c(id) { return document.getElementById(id); } var totalPriceTotal = 0; var totalDurationTotal = 0; var totalDivesTotal = 0; var totalHireTotal = 0; for (var id in productIds) { // multiply by 1 to make sure it's a number totalPriceTotal += $c('product_price_total_' + id).value * 1; totalDurationTotal += $c('product_duration_total_' + id).value * 1; totalDivesTotal += $c('product_dives_total_' + id).value * 1; totalHireTotal += $c('product_hire_total_' + id).value * 1; } $c('GT_total_price').value = totalPriceTotal; $c('GT_total_duration').value = totalDurationTotal; $c('GT_total_dives').value = totalDivesTotal; $c('GT_total_hire').value = totalHireTotal; function $c(id) { return document.getElementById(id); } } </code></pre> <p>working sample at <a href="http://www.divethegap.com/update/diving-trips/adventure-training/#level_01" rel="nofollow">http://www.divethegap.com/update/diving-trips/adventure-training/#level_01</a> (click on beginners) Many Thanks</p>
    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.
    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