Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery if or while loops
    primarykey
    data
    text
    <p>I haven't done much (or any) jQuery. I found the following script on here to, but I have a question. All the attempts I've tried while searching this site have ruined the script. I only want it sum the values of the other columns if the checkbox is checked. </p> <p>Here is an example table:</p> <pre><code>&lt;table id="sum_table" class="example"&gt; &lt;thead&gt; &lt;tr class="titlerow"&gt; &lt;td class="table-sortable:numeric"&gt;Apple&lt;/td&gt; &lt;td class="table-sortable:numeric"&gt;Orange&lt;/td&gt; &lt;td class="table-sortable:numeric"&gt;Watermelon&lt;/td&gt; &lt;td class="table-sortable:numeric"&gt;Turtle&lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tr&gt; &lt;td class="rowDataSd"&gt;52&lt;/td&gt; &lt;td class="rowDataSd"&gt;911&lt;/td&gt; &lt;td class="rowDataSd"&gt;911&lt;/td&gt; &lt;td&gt;&lt;input type="checkbox" name="cb" value="1"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="rowDataSd"&gt;989&lt;/td&gt; &lt;td class="rowDataSd"&gt;24&lt;/td&gt; &lt;td class="rowDataSd"&gt;911&lt;/td&gt; &lt;td&gt;&lt;input type="checkbox" name="cb" value="1"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="rowDataSd"&gt;989&lt;/td&gt; &lt;td class="rowDataSd"&gt;911&lt;/td&gt; &lt;td class="rowDataSd"&gt;911&lt;/td&gt; &lt;td&gt;&lt;input type="checkbox" name="cb" value="1"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tfoot&gt; &lt;tr class="totalColumn"&gt; &lt;td class="totalCol"&gt;Total:&lt;/td&gt; &lt;td class="totalCol"&gt;Total:&lt;/td&gt; &lt;td class="totalCol"&gt;Total:&lt;/td&gt; &lt;td class="totalCol"&gt;Total:&lt;/td&gt; &lt;/tr&gt; &lt;/tfoot&gt; </code></pre> <p>Here's the script:</p> <pre><code>$('#sum_table tr:first td').each(function(){ var $td = $(this); var colTotal = 0; $('#sum_table tr:not(:first,.totalColumn)').each(function(){ colTotal += parseInt($(this).children().eq($td.index()).html(),10); }); $('#sum_table tr.totalColumn').children().eq($td.index()).html('Total: ' + colTotal); }); </code></pre> <p>Where would I put an &amp;&amp;, and what exactly would that &amp;&amp; be?</p> <p>I've tried adding &amp;&amp;s, but I'm just not familiar with how to read jQuery. I'd love to learn it and I thought this would be a simple project. Guess not. As always, any help is greatly appreciated.</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.
 

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