0 Replies - 263 Views - Last Post: 22 March 2011 - 11:14 PM

#1 madhabca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-March 11

How to add table last row

Posted 22 March 2011 - 11:14 PM

hi everybody,

How to add the sum value in the table last row. for example i added five items in the table i need a total for qty, amt,dis.amt,tax amt and etc., an the six row. how can i do the process in client side using javascript. my coding is below
// to add the multiple rows on btn click
var i = 1;
    var rowcount = 5;
    var valdisper, valdisamt, valsalprice, valqty, valval, valvatper, valamt, valmrp, valnet, valgross, valitem, valcode;
    var valuom;
    valcode = document.getElementById("txtcode").value;
    valitem = document.getElementById("txtdesc").value;
    valmrp = document.getElementById("txtmrp").value;
    valsalprice = document.getElementById("txtsalp").value;
    valqty = document.getElementById("txtqty").value;
    valuom = document.getElementById("sel2").value;
    valval = document.getElementById("txtval").value;
    valdisper = document.getElementById("txtdis").value;
    valdisamt = document.getElementById("txtdisamt").value;
    valamt = document.getElementById("txttax").value;
    valnet = document.getElementById("txtnet").value;
    valvatper = document.getElementById("sel").value;
    valgross = document.getElementById("txtgross").value;
//    if (rowcount > 2) {
//        removeRow(this);
//    }
    if (valcode != "" && valcode != null) {
       
            var tbody = document.getElementById
        (id).getElementsByTagName("TBODY")[0];
            var row = document.createElement("TR")
            var td1 = document.createElement("TD")
            td1.appendChild(document.createTextNode(i))
            i += 1;
            var td2 = document.createElement("TD")
            td2.appendChild(document.createTextNode(valcode))
            var td3 = document.createElement("TD")
            td3.appendChild(document.createTextNode(valitem))
            var td4 = document.createElement("TD")
            td4.appendChild(document.createTextNode(valmrp))
            var td5 = document.createElement("TD")
            td5.appendChild(document.createTextNode(valsalprice))
            var td6 = document.createElement("TD")
            td6.appendChild(document.createTextNode(valqty))

            var td7 = document.createElement("TD")
            td7.appendChild(document.createTextNode(valuom))
            var td8 = document.createElement("TD")
            td8.appendChild(document.createTextNode(valval))

            var td9 = document.createElement("TD")
            td9.appendChild(document.createTextNode(valdisamt))

            var td10 = document.createElement("TD")
            td10.appendChild(document.createTextNode(valamt))

            var td11 = document.createElement("TD")
            td11.appendChild(document.createTextNode(valnet))
            row.appendChild(td1);
            row.appendChild(td2);
            row.appendChild(td3);
            row.appendChild(td4);
            row.appendChild(td5);
            row.appendChild(td6);
            row.appendChild(td7);
            row.appendChild(td8);
            row.appendChild(td9);
            row.appendChild(td10);
            row.appendChild(td11);
            tbody.appendChild(row);

          }
//to find the sum value for qty,amt,dis.amt,tax amt,net.amt
 var tbl = document.getElementById(id);
            var lastRow = tbl.rows.length;
            alert(lastRow);
            if (lastRow =lastRow ) {
                var iteration = lastRow;
                var row2 = tbl.insertRow(lastRow);
                totqty = parseFloat(totqty) + parseFloat(valqty);
                totdisamt = parseFloat(totdisamt) + parseFloat(valdisamt);
                tottaxamt = parseFloat(tottaxamt) + parseFloat(valamt);
                totvalamt = parseFloat(totvalamt) + parseFloat(valval);
                totnet = parseFloat(totnet) + parseFloat(valnet);
                row2 = document.createElement("TR")
                var td12 = row2.insertCell(0);
                td12.appendChild("")
                var td13 = row2.insertCell(1);
                td13.appendChild("Total");
                var td14 = row2.insertCell(2);
                td14.appendChild("");
                var td15 = row2.insertCell(3);
                td15.appendChild("");
                var td16 = row2.insertCell(4);
                td16.appendChild("");

                var td17 = row2.insertCell(5);
                td17.appendChild(totqty);
                var td18 = row2.insertCell(6);
                td18.appendChild("");
                var td19 = row2.insertCell(7);
                td19.appendChild(totvalamt);

                var td20 = row2.insertCell(8);
                td20.appendChild(totdisamt);

                var td21 = row2.insertCell(9);
                td21.appendChild(tottaxamt);

                var td22 = row2.insertCell(10);
                td22.appendChild(totnet);
                row2.appendChild(td12);
                row2.appendChild(td13);
                row2.appendChild(td14);
                row2.appendChild(td15);
                row2.appendChild(td16);
                row2.appendChild(td17);
                row2.appendChild(td18);
                row2.appendChild(td19);
                row2.appendChild(td20);
                row2.appendChild(td21);
                row2.appendChild(td22);
                tbody.appendChild(row2);


the above the coding return total for each row.any one can help me.how to bind the total value in last row of the table.


Thank you.

Mod edit - Please :code:

This post has been edited by BetaWar: 22 March 2011 - 11:59 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1