title: How to get the text value from textbox which is in Gridview using Javascript
body: <p>Hi all I have written the following script to get the value from the <code>textbox</code> which is in <code>GridView</code> but I am getting some value as <code>NaN</code>can some one tell where I went wrong</p>
  
  <p>This is my sample script</p>
  
  <pre><code>var grid = document.getElementById("&lt;%=grdInvoice.ClientID%&gt;");
              var inputs = grid.getElementsByTagName("input");
              for (var i = 0; i &lt; inputs.length; i++) {
                  if (inputs[i].type == "text") {
                      if (inputs[i].name.indexOf("txtAmount").value != "") {
                          alert("Not Null");
                          amnt = parseInt(inputs[i].name.indexOf("txtAmount").value);
                          alert(amnt.toString()); // Getting Nan here
                          //var v = document.getElementById('&lt;%= lblTotal.ClientID %&gt;').value;
                      }
                  }
              }
  </code></pre>
  
  <p>My grid is as follows</p>
  
  <pre><code> ddl    Quantity  desc     Rate    Amount
          1         d        10      10
          2         d        20      40
  </code></pre>
  
  <p>Like that some empty rows will also be there I need to sum the <code>Amount</code> and display</p>
  
  <p>My grid view</p>
  
  <pre><code>&lt;asp:GridView ID="grdInvoice" runat="server" AutoGenerateColumns="False" GridLines="None"
                          Width="650px" CellPadding="2" CellSpacing="1" ForeColor="#333333" CssClass="inv_grid_data"
                          OnSelectedIndexChanged="grdInvoice_SelectedIndexChanged" OnSelectedIndexChanging="grdInvoice_SelectedIndexChanging"
                          Style="font-family: verdana; font-size: 9px;"&gt;
                          &lt;RowStyle BackColor="#f1f1f2" ForeColor="#333333" BorderColor="#333333" BorderStyle="Solid"
                              BorderWidth="1px" /&gt;
                          &lt;HeaderStyle CssClass="inv_grid_hed" BackColor="#f2f2f2" ForeColor="black" Font-Names="Verdana,Arial,Helvetica,sans-serif"
                              Font-Size="9px" Height="15px" Font-Bold="false" /&gt;
                          &lt;AlternatingRowStyle CssClass="tr2" BackColor="White" ForeColor="#284775" /&gt;
                          &lt;Columns&gt;
                              &lt;asp:TemplateField HeaderText="Item Name" HeaderStyle-Width="140"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:DropDownList ID="ddlItems" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlItems_SelectedIndexChanged"
                                          DataTextField="LineItemName" DataValueField="LineItemName" CssClass="txt_box_ssm_drop"
                                          Width="100%" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="12px"&gt;
                                      &lt;/asp:DropDownList&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;HeaderStyle Width="180px" /&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Quantity"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:TextBox ID="txtQuantity" CssClass="txt_box_ssm_big" runat="server" Width="100%"&gt;&lt;/asp:TextBox&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;HeaderStyle Width="100px" /&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Description"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:TextBox ID="txtDescription" CssClass="txt_box_ssm_big" runat="server" Width="100%"&gt;&lt;/asp:TextBox&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;%--&lt;ItemStyle Height="11px" Width="100px" /&gt; --%&gt;
                                  &lt;HeaderStyle Width="260px" /&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Rate"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:TextBox ID="txtRate" ReadOnly="true" CssClass="txt_box_ssm_big" runat="server"
                                          Width="100%"&gt;&lt;/asp:TextBox&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;HeaderStyle Width="100px" /&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Amount"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:TextBox ID="txtAmount" runat="server" CssClass="txt_box_ssm_big" Width="100%"&gt;&lt;/asp:TextBox&gt;
                                      &lt;%--&lt;asp:Label ID="lblamount" runat="server" Text='&lt;%# Eval("Amount") %&gt;'/&gt;--%&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;HeaderStyle Width="100px" /&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Delete"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;%--&lt;asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/icon_delete.gif" OnClick="RowDelete_Click" OnClientClick="msg('Can you get there from here?','This is a Title')"/&gt;--%&gt;
                                      &lt;asp:ImageButton ID="RowDelete" runat="server" ImageUrl="~/images/icon_delete.gif"
                                          OnClick="RowDelete_Click" OnClientClick="return showConfirm()" Style="margin-left: 15px;" /&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:CommandField ShowSelectButton="true" ButtonType="image" SelectImageUrl="~/Invoiceimages/Copy-32(1).png"
                                  SelectText="Copy" HeaderText="Copy" /&gt;
                          &lt;/Columns&gt;
                          &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
                          &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
                          &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt;
                          &lt;EditRowStyle BackColor="#999999" /&gt;
                      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>My original script initially I will add AMount in the grid view based on user quantity after that I Would like to display the total amount in the grid to a label</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function multiplication(txtQuantity, txtRate, txtAmount) {
              var weight = document.getElementById(txtQuantity).value;
              var rate = document.getElementById(txtRate).value;
              document.getElementById(txtAmount).value = weight * rate;
              var amnt = 0;
  //            var Grid_Table = document.getElementById('&lt;%= grdInvoice.ClientID %&gt;');
  //            for (var row = 1; row &lt; Grid_Table.rows.length; row++) {
  
  //                var qty = 0;
  
  //                for (var col = 0; col &lt; Grid_Table.rows[row].cells.length; col++) {
  
  //                    var cellcollectin = Grid_Table.rows[row].cells[col];
  
  //                    for (var j = 0; j &lt; cellcollectin.childNodes.length; j++) {
  
  //                        if (cellcollectin.childNodes[j].type == "text") {
  
  //                            if (cellcollectin.childNodes[j].name.indexOf("txtAmount") &gt; 1) {
  //                                if (cellcollectin.childNodes[j].value != "") {
  //                                    qty = parseInt(cellcollectin.childNodes[j].value);
  //                                    amnt = amnt + qty;
  //                                }
  //                            }
  //                        }
  //                    }
  //                }
  //            }
                          var grid = document.getElementById("&lt;%=grdInvoice.ClientID%&gt;");
                          var inputs = grid.getElementsByTagName("input");
                          for (var i = 0; i &lt; inputs.length; i++) {
                              if (inputs[i].type == "text") {
                                  if (inputs[i].name.indexOf("txtAmount").value != "") {
                                      alert("Not Null");
                                      amnt = grid.rows[i].cells[1].childNodes[0].value;
                                      //amnt = parseInt(inputs[i].name.indexOf("txtAmount").value);
                                      alert(amnt.toString());
                                      //var v = document.getElementById('&lt;%= lblTotal.ClientID %&gt;').value;
                                  }
                              }
                          }
              document.getElementById('&lt;%= lblTotal.ClientID %&gt;').innerHtml = amnt.toString();
          }
      &lt;/script&gt;
  </code></pre>