Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery / javascript to sum field only if checkbox on same row is checked
    primarykey
    data
    text
    <p>I have a jquery / javascript function that totals the number of cubes in my order. this works 100% and is below.</p> <pre><code>function calculateTotalVolume() { var grandTotalCubes = 0; $("table.authors-list").find('input[name^="cubicvolume"]').each(function () { grandTotalCubes += +$(this).val(); }); $("#grandtotalcubes").text(grandTotalCubes.toFixed(2)); } </code></pre> <p>as mentioned the above works great. I need a second function to total the same field but only if an checkbox named treated is checked. each row has the checkbox named treated but as the table is dynamically generated, a counter is appended to the name each time hence my use of <code>name^="treated"</code></p> <p>I am after something like below but this doesn't work:</p> <pre><code>function calculateTotalTreatedVolume() { var grandTotaltreatedCubes = 0; $("table.authors-list").find('input[name^="cubicvolume"]').each(function () { if($("table.authors-list").find('checkbox[name^="treated"]').checked){ alert('10'); grandTotaltreatedCubes += +$(this).val(); } }); $("#grandtotaltreatedcubes").text(grandTotaltreatedCubes.toFixed(2)); } </code></pre> <p>help appreciated as always.</p> <p><strong>UPDATE</strong></p> <p>Rendered HTML output [1 dynamic row added]: (Still in development so very rough, please excuse it)</p> <pre><code>&lt;table class="authors-list" border=1&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt;&lt;td&gt;Product&lt;/td&gt;&lt;td&gt;Price/Cube&lt;/td&gt;&lt;td&gt;Qty&lt;/td&gt;&lt;td&gt;line total cost&lt;/td&gt;&lt;td&gt;Discount&lt;/td&gt;&lt;td&gt;Cubes per bundle&lt;/td&gt;&lt;td&gt;pcs per bundle&lt;/td&gt;&lt;td&gt;cubic vol&lt;/td&gt;&lt;td&gt;Bundles&lt;/td&gt;&lt;td&gt;&lt;input type="checkbox" class="checkall"&gt; Treated&lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;a class="deleteRow"&gt; &lt;img src="http://devryan.tekwani.co.za/application/assets/images/delete2.png" /&gt;&lt;/a&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="product" name="product" /&gt; &lt;input type="hidden" id="price" name="price" readonly="readonly"/&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="adjustedprice" name="adjustedprice" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="qty" name="qty" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="linetotal" name="linetotal" readonly="readonly"/&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="discount" name="discount" /&gt;&lt;/td&gt; &lt;td&gt; &lt;input type="text" id="cubesperbundle" name="cubesperbundle" &gt; &lt;/td&gt; &lt;td&gt; &lt;input type="text" id="pcsperbundle" name="pcsperbundle" &gt; &lt;/td&gt; &lt;td&gt; &lt;input type="text" id="cubicvolume" name="cubicvolume" size='5' disabled&gt; &lt;/td&gt; &lt;td&gt;&lt;input type="text" id="totalbundles" name="totalbundles" size='5' disabled &gt;&lt;/td&gt; &lt;td valign="top" &gt;&lt;input type="checkbox" id="treated" name="treated" &gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;tfoot&gt; &lt;tr&gt; &lt;td colspan="15"&gt;&lt;input type="button" id="addrow" value="Add Product" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3"&gt;Grand Total: R&lt;span id="grandtotal"&gt;&lt;/span&gt;&lt;/td&gt; &lt;td colspan="2"&gt;Ave Discount: &lt;span id="avediscount"&gt;&lt;/span&gt;%&lt;/td&gt; &lt;td colspan="1"&gt;Total Cubes: &lt;span id="grandtotalcubes"&gt;&lt;/span&gt;&lt;/td&gt; &lt;td colspan="15"&gt;Treated Cubes: &lt;span id="grandtotaltreatedcubes"&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="15"&gt;&lt;textarea rows="1" cols="50" placeholder="Specific Comments"&gt;&lt;/textarea&gt;&lt;textarea rows="1" cols="20" placeholder="Customer Reference"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tfoot&gt; &lt;/table&gt; </code></pre>
    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. 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