Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use the following code:</p> <p>JS:</p> <pre><code>function refreshPrices() { var currentTotalValue = 0; $("#results div").each(function() { if (!isNaN(parseInt($(this).find("span").text().substring(1)))) { currentTotalValue += parseInt($(this).find("span").text().substring(1)); } }); $("#totalValue").text("$" + currentTotalValue) } </code></pre> <p>To use it, store all your "<code>result*</code>" containers in a container, which will make the output easier to iterate through with jQuery [since only one major selector (<code>"#results"</code>) is needed to grab the results in all of the "<code>result*</code>" containers].</p> <pre><code>&lt;div id="results"&gt; &lt;div id="result"&gt; &lt;/div&gt; &lt;div id="result2"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>And whenever the user interacts with a checkbox, <code>refreshPrices()</code> should be called.</p> <p>HTML:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td style="width: 13px"&gt; &lt;input id="1" type="checkbox" name="" onClick="" /&gt; &lt;/td&gt; &lt;td&gt; &lt;h4&gt;PDF Document&lt;/h4&gt; &lt;p&gt; Already have your own menu or flyer? Include it in your App &lt;/p&gt; &lt;/td&gt; &lt;td class="cost" id="pdf-cost"&gt;£99.99 per document&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width: 13px"&gt; &lt;input id="2" type="checkbox"/&gt; &lt;/td&gt; &lt;td&gt; &lt;h4&gt;Video&lt;/h4&gt; &lt;p&gt; If you've already got videos on your website, these can be included within your App too. &lt;/p&gt; &lt;/td&gt; &lt;td class="cost"&gt;£149.99 per video&lt;/td&gt; &lt;/tr&gt; &lt;table&gt; &lt;br&gt; &lt;br&gt; &lt;div id="totalValu"&gt;Total Value: &lt;span id="totalValue"&gt;$0&lt;/span&gt;&lt;/div&gt; &lt;div id="results"&gt; &lt;div id="result"&gt; &lt;/div&gt; &lt;div id="result2"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>JS:</p> <pre><code>$(document).ready(function() { $('#1').click(function() { //var row = $(this); if (($(this).attr('checked')) == 'checked') { $('#result').append("-PDF Document &lt;html&gt;&lt;span style=float:right&gt;$190&lt;/span&gt;&lt;/html&gt;"); } else { $('#result').text(""); } refreshPrices(); }); $('#2').click(function() { if (($(this).attr('checked')) == 'checked') { $('#result2').append("-Video &lt;html&gt;&lt;span style=float:right&gt;$150&lt;/span&gt;&lt;/html&gt; "); } else { $('#result2').text(""); } refreshPrices() }); });​ </code></pre> <p>JSFiddle: <a href="http://jsfiddle.net/BA5rX/7/" rel="nofollow">http://jsfiddle.net/BA5rX/7/</a></p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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