Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have made a dynamic table where there want to be two column I want the summation of rows of each column I have created only column but I


What I have tried:

<script language="javascript">
     function addRow(tableID)
         {
           var table = document.getElementById(tableID);
           var rowCount = table.rows.length;
           if (rowCount < 4)
           {
            var row = table.insertRow(rowCount);

          var colCount = table.rows[0].cells.length;
          row.id = "row_" + rowCount;
          for (var i = 0; i < colCount; i++) {
            var newcell = row.insertCell(i);
            newcell.outerHTML = table.rows[0].cells[i].outerHTML;
          }
          var listitems = row.querySelectorAll("input, select");

          for (i = 0; i < listitems.length; i++) {
            listitems[i].setAttribute("oninput", "calculate('" + row.id + "')");
            
          }
        } else {
          alert("");
        }
      }
         function calculate(elementID)
         {
          var mainRow = document.getElementById(elementID);
        var myBox1 = mainRow.querySelectorAll("[name=myBox1]")[0].value;
    
        var myresult1 = myBox1;
         myBox1.
        var sumValue = 0;
        
        for (i = 0; i < totalContainers.length; ++i) {
          sumValue += parseInt(totalContainers[i].value);
        }
        sumContainer.textContent = sumValue;
         var mainRow1 = document.getElementById(elementID);
        var myBox2 = mainRow1.querySelectorAll("[name=myBox2]")[0].value;
    
        var myresult2 = myBox2;
         myBox2.value = myresult2;
          var sumContainer1 = document.getElementById("mybox1");
          
        var totalContainers1 = document.querySelectorAll("[name=myBox2]"), i1;
        var sumValue1 = 0;
        
        for (i1 = 0; i1 < totalContainers.length; ++i1) {
          sumValue1 += parseInt(totalContainers1[i1].value);
        }
        sumContainer1.textContent = sumValue1;
        
      }
         
    </script>
Posted

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