Dorababu Meka

Dorababu Meka

  • 226
  • 8.3k
  • 1.7m

How to sum textbox value from gridview and display total in a label using javascript

Apr 12 2012 11:08 AM
I am having a gridview initially follows









I would like to display the sum in the label available on the from


This is what I have written to display Amount in the amount textbox

<script type="text/javascript">
        function multiplication(txtQuantity, txtRate, txtAmount) {
            var weight = document.getElementById(txtQuantity).value;
            var rate = document.getElementById(txtRate).value;
            document.getElementById(txtAmount).value = weight * rate; Here I will assign amount to gridview textbox Amount
            var Grid_Table = document.getElementById('<%= grdInvoice.ClientID %>');


            for (var row = 1; row < Grid_Table.rows.length; row++) {


                var qty = 0, rate = 0;


                for (var col = 0; col < Grid_Table.rows[row].cells.length; col++) {


                    var cellcollectin = Grid_Table.rows[row].cells[col];


                    for (var j = 0; j < cellcollectin.childNodes.length; j++) {


                        if (cellcollectin.childNodes[j].type == "text") {


                            if (cellcollectin.childNodes[j].name.indexOf("txtAmount") >= 1) {
                                qty = parseInt(cellcollectin.childNodes[j].value);
                                alert(qty);
                            }
                        }


                    }
                }
            }
        }
    </script>

Can any one help how to diplay the total sum of amount in the label


Answers (1)