Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i created a html table using the code as below.
JavaScript
 var sString = "";
    sString += "<table cellpadding='4' cellspacing='0' class='tableGgrid_' style='text-align: center;width: 100%;'>";
    sString += "<tr class='HeaderCell'>";
    sString += "<td style='border-width: 1px; width:5%; border-right-style: solid;";
    sString += "border-bottom-style: solid; border-color: #4B6C9E;' align='left'>";
    sString += "">Employee Name";
    sString += "</td>";
    sString += "<td style=' removed: pointer; border-width: 1px; width: 14%; border-right-style: solid;";
    sString += "border-bottom-style: solid; border-color: #4B6C9E;' align='left'>";
    sString += "^__b class="normalText">Employee ID";
    sString += "</tr>";
    for(i=0;i<oTable.Rows.length;i++)
    {
           
            sString += "<tr  class='" + sClass + "' >";
            sString += "<td style='border-width: 1px;  border-right-style: solid;";
            sString += "border-bottom-style: solid; border-color: #4B6C9E;' align='left'>";
            sString += "<span class='wordwrap'>" +i + "</span>";
            sString += "</td>";
            sString += "<td style='border-width: 1px;  border-right-style: solid;";
            sString += "border-bottom-style: solid; border-color: #4B6C9E;' align='left'>";
            sString += "<span class='wordwrap'>" + trimAll(oTable.Rows[i].empName.replace(/\\/gi, '\\')) + "</span>";
            sString += "</td>";           
            sString += "<td style='border-width: 1px;  border-right-style: solid;";
            sString += "border-bottom-style: solid; border-color: #4B6C9E;' align='left'>";
            sString += "<span class='linkText'>" + trimAll(oTable.Rows[i].cmpId) + "</span>";
            sString += "</td>";           
            sString += "</tr>";
              
 
    }

   sString += "</table>";
document.getElementById("divAllReports").innerHTML = sString;



i want to find the sum of columns of the above table. how can find it?

Thanks..
Posted
Comments
Karthik_Mahalingam 17-Jan-14 3:45am    
pls post the HTML which is rendered in the screen

You're creating the table a row at a time, so add the values for each column up as you create it.
 
Share this answer
 
You could try with Jquery


XML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <div id="divAllReports"></div>
    <div id="divSum"></div>
    <script src="jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(
            function() {
                var sString = "";
                sString += "<table>";

                sString += "<tr>";
                    sString += "<td>ABC</td>";
                    sString += "<td>300</td>";
                sString += "</tr>";

                sString += "<tr>";
                sString += "<td>PQR</td>";
                sString += "<td>200.75</td>";
                sString += "</tr>";


                sString += "<tr>";
                sString += "<td>xyz</td>";
                sString += "<td>223</td>";
                sString += "</tr>";

                sString += "<tr>";
                sString += "<td>xyz</td>";
                sString += "<td></td>";
                sString += "</tr>";


                sString += "<tr>";
                sString += "<td>xyz</td>";
                sString += "<td>2</td>";
                sString += "</tr>";

                sString += "</table>";
                document.getElementById("divAllReports").innerHTML = sString;


                var sum = 0;

                $('td:nth-child(2)').each(function () {

                    var value = Number($(this).html());
                    if (!isNaN(value)) sum += value;

                });

                $('#divSum').html(sum);
                //
            }
        );

    </script>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900