Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery sum events on TD click
    primarykey
    data
    text
    <p>I have a simple table to simulate a Gantt chart. The idea is that each TD clicking trigger a sum of values stored in an hidden input text (an array of values), available in a TH (first son of TR tag). The row sum of these values, is shown on a final TD.</p> <p>Next, the code table:</p> <pre><code> &lt;table width="100%" cellspacing="0" class="datagrid_ppal"&gt; &lt;tbody&gt; &lt;tr class="encabezado"&gt; &lt;th rowspan="2" scope="col" width="15%"&gt;Area&lt;/th&gt; &lt;th colspan="7" scope="col"&gt;Month&lt;/th&gt; &lt;/tr&gt; &lt;tr class="encabezado"&gt; &lt;th scope="col" width="2%"&gt;1&lt;/th&gt; &lt;th scope="col" width="2%"&gt;2&lt;/th&gt; &lt;th scope="col" width="2%"&gt;3&lt;/th&gt; &lt;th scope="col" width="2%"&gt;4&lt;/th&gt; &lt;th scope="col" width="2%"&gt;5&lt;/th&gt; &lt;th scope="col" width="2%"&gt;...&lt;/th&gt; &lt;th scope="col" width="2%"&gt;31&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th scope="row"&gt;Area 1&lt;input name="line_config" type="hidden" value="0,5,50" /&gt;&lt;/th&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt;...&lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th scope="row"&gt;Area 2 &lt;input name="line_config" type="hidden" value="0,0,10" /&gt;&lt;/th&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;td class="gantt"&gt;...&lt;/td&gt; &lt;td class="gantt"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr class="encabezado"&gt; &lt;th scope="row"&gt;Total&lt;/th&gt; &lt;td class="total_dia"&gt; &lt;/td&gt; &lt;td class="total_dia"&gt; &lt;/td&gt; &lt;td class="total_dia"&gt; &lt;/td&gt; &lt;td class="total_dia"&gt; &lt;/td&gt; &lt;td class="total_dia"&gt; &lt;/td&gt; &lt;td class="total_dia"&gt;...&lt;/td&gt; &lt;td class="total_dia"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>The array of values works as follows: array [0]: Off; array [1]: preoperative; array [2]: Operating.</p> <p>This is the jQuery code I use to differentiate cells that are pre-operational and operational. If a cell is inactive, the area is off:</p> <pre><code>$(document).ready(function() { $('td.gantt').click(function() { $(this).toggleClass('preop'); }); $('td.gantt').dblclick(function() { $(this).toggleClass('operating'); }); }); </code></pre> <p>Inactive TD always sum to the total. What I want to do? Simple: 1. That jQuery always sum TH input value[0], if the TD is not clicked (inactive). 2. When I click, or double click, a TD.gantt jQuery fetch the TH input value[1], and add it to the total.</p> <p>If anyone can help with the whole problem, o a parcial, I would really appreciate.</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