Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:43:22+00:00 2026-06-08T11:43:22+00:00

Good afternoon, in my php/mysql page I have dynamic tables with a row total

  • 0

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?

Here is the js;

<script type="text/javascript" src="../js/prototype.js"></script>

<script language="javascript">
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; 
  }); 
}
</script>

And dynamic table + form to hide columns;

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

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

Many thanks for looking..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:43:24+00:00Added an answer on June 8, 2026 at 11:43 am

    Then you have to parse your table using Javascript, just after toggling the column.

    The easiest way would be to give a class to each rows and each cell. Take care not to use ids for you cells as they won’t be unique. Don’t use names either, as they are more dedicated to forms and inputs.

    <tr class="row">
      <td class="tcol1"><?php echo $row_Recordset1['Adviser']; ?></td>
      <td class="tcol2"><?php echo $row_Recordset1['Jan'    ]; ?></td>
      <td class="tcol3"><?php echo $row_Recordset1['Feb'    ]; ?></td>
      <td class="total"><?php echo $row_Recordset1['Total'  ]; ?></td>
    </tr>
    

    Then you would parse your rows and cells like the following (prototype.js style) :

    $$('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) : 0;
      });
    
      // Write the total in the total cell
      row.down('.total').textContent = total;
    });
    

    That should work.

    You could have a analog code written with other JS frameworks, like jquery, needless to say that without any framework it would be quite less trivial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good afternoon in my timezone. I have a table with four tr and each
Good Afternoon, I have a html aspx page that has many many div elements.
Good afternoon, I wish to have a script that will look for all files
Good Afternoon, I have a web application (MVC3) which has master page. I have
Good Afternoon all , I have downloaded data from a web service and im
Good afternoon, I have a quick 'top level' question regarding the usage of Facebook
Good afternoon I have a table that has customer id, name, computer, laptop, blah,
Good afternoon to all, I have this scenario: I am using SQL Server 'BulkInsert'
Good afternoon all, I have a class which looks like this: public class Grapheme
Good Afternoon, I am trying to get these results into arrays in PHP so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.