You must Sign In to post a response.
  • Category: JQuery

    How to find sum of 2 columns in html table using jquery

    Hi following is my html table

    <table id="grdtable">
    <tr><td>Charge</td><td>start</td><td>End</td><td>No</td><td>Total</td></tr>
    <tr><td>7</td><td>100</td><td>200</td><td>100</td><td>700</td></tr>
    <tr><td>8</td><td>10</td><td>100</td><td>90</td><td>720</td></tr>
    <tr><td>9</td><td>20</td><td>50</td><td>30</td><td>270</td></tr>
    </table>

    its output is as follows

    Charge start End No Total
    7 100 200 100 700
    8 10 100 90 720
    9 20 50 30 270

    my requiremt is on the click event of button i want add the the result in a variable using each function
    var str="";
    just like

    str= 7 * 100=700
    8*90=720
    9*30=270
    means multiplying first column with fourth column

    how to do this

    Regards

    Baiju
  • #768347
    Here is the example of code snippet for your requirement How to find sum of html table using jquery
    $("#sum_table tr:last td:not(:first,:last)").text(function(i){
    var t = 0;
    $(this).parent().prevAll().find("td:nth-child("+(i+2)+")").each(function(){
    t += parseInt( $(this).text(), 10 ) || 0;
    });
    return "Total: " + t;
    });


Sign In to post your comments