Link to home
Start Free TrialLog in
Avatar of dennis231
dennis231

asked on

javascript for calculating total for a column

In my HTML document, I have a table contains following fields:

StudentID|ExamScore1|ExamScore2
00001|90|100
00002|70|100
00003|60|80

How do I write a javascript to calculate the total for ExamScore1 and ExamScore2 columns? So my table will look like this:
00001|90|100
00002|70|100
00003|60|80
Total|220|280

Thanks for your help.



Avatar of sunithnair
sunithnair

You mean HTML table? If so then is the number of rows going to remain the same?
Avatar of dennis231

ASKER

Yes, it is a html table, but the number of rows will be changed from time to time.

Sample table:
<table border="1" width="822">
    <tr>
        <td width="266">StudentID</td>
        <td width="266">
            <p><span class="value">ExamScore1</span></p>
        </td>
        <td width="266">
            <p><span class="value">ExamScore2</span></p>
        </td>
    </tr>
    <tr>
        <td width="266">
            <p><span class="value">00001</span></p>
        </td>
        <td width="266">90</td>
        <td width="266">100</td>
    </tr>
    <tr>
        <td width="266">
            <p><span class="value">00002</span></p>
        </td>
        <td width="266">70</td>
        <td width="266">100</td>
    </tr>
    <tr>
        <td width="266">
            <p><span class="value">00003</span></p>
        </td>
        <td width="266">60</td>
        <td width="266">80</td>
    </tr>
    <tr>
        <td width="266" bgcolor="aqua">Total</td>
        <td width="266" bgcolor="aqua"><b>220 &nbsp;<-calculate total</b></td>
        <td width="266" bgcolor="aqua">
            <p><b>280 <-calculate total</b></p>
        </td>
    </tr>
</table>
I can do it for you tomorrow if you can wait. Time for me to sleep now..
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial