Show/Hide dynamic table columns with Totals
<p>Good afternoon, in my php/mysql page I have dynamic tables with a row total for each row. I have used a show/hide script to hide certain columns which is great but I would really like the row total to update when column is hidden, iin example below if I hide say Jan it should deduct the value in that column row and update the total column? </p>

<p>Here is the js;</p>

<pre><code>&lt;script type="text/javascript" src="../js/prototype.js"&gt;&lt;/script&gt;

&lt;script language="javascript"&gt;
function toggleVis(button) { 
  // Toggle column 
  cells = $$('.t'+button.name); 
  cells.invoke(button.checked ? 'show' : 'hide'); 

  // Recaulculate total 
  $$('tr.row').each(function(row) { 
    // Initialise to zero 
    var total = 0; 
    row.down('.total').textContent = total; 

    // Sum all visible cells 
    row.select('td').each(function(cell) { 
      total += cell.visible() ? parseInt(cell.textContent, 10) : 0;
    }); 

    // Write the total in the total cell 
    row.down('.total').textContent = total; 
  }); 
}
&lt;/script&gt;
</code></pre>

<p>And dynamic table + form to hide columns;</p>

<pre><code>&lt;form name="tcol" onsubmit="return false"&gt;
  Show columns
  &lt;input type=checkbox name="col1" onclick="toggleVis(this.name)" checked&gt; 1
  &lt;input type=checkbox name="col2" onclick="toggleVis(this.name)" checked&gt; 2
  &lt;input type=checkbox name="col3" onclick="toggleVis(this.name)" checked&gt; 3
&lt;/form&gt;

&lt;table border="1" cellpadding="1" cellspacing="1"&gt;
  &lt;tr&gt;
    &lt;td class="tcol1"&gt;Adviser&lt;/td&gt;
    &lt;td class="tcol2"&gt;Jan&lt;/td&gt;
    &lt;td class="tcol3"&gt;Feb&lt;/td&gt;
    &lt;td class="total"&gt;Total&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php do { ?&gt;
    &lt;tr class="row"&gt;
      &lt;td class="tcol1"&gt;&lt;?php echo $row_Recordset1['Adviser']; ?&gt;&lt;/td&gt;
      &lt;td class="tcol2"&gt;&lt;?php echo $row_Recordset1['Jan'    ]; ?&gt;&lt;/td&gt;
      &lt;td class="tcol3"&gt;&lt;?php echo $row_Recordset1['Feb'    ]; ?&gt;&lt;/td&gt;
      &lt;td class="total"&gt;&lt;?php echo $row_Recordset1['Total'  ]; ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?&gt;
&lt;/table&gt;
</code></pre>

<p>Many thanks for looking..</p>
