Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridview with textbox qty and rate and amt

when the user enters qty and then rate on blur of rate textbox i need amt to be calculated

i hve script for the same but i get error 'function expected' in line JavaScript runtime error: Function expected

GVRow1.cells(child1).childNodes(0).type
C#
function CalAmt(SelectRow) {

              var GridRow= SelectRow.parentNode.parentNode;

             var row = SelectRow.parentNode.parentNode;
             var Qty;
             var Rate;

             for (var child1 = 0; child1 <= GridRow.cells.length - 1; child1++)
        {
                 alert(GridRow.cells(child1).childNodes(0).type);// error
                 if (GridRow.cells(child1).childNodes(0).type == "text")
                 {
                     if (GridRow.cells(child1).childNodes(0).id.indexOf("txtqty") > 0)
                      {
                          Qty = GridRow.cells(child1).childNodes(0).value;
                      }

                      if (GridRow.cells(child1).childNodes(0).id.indexOf("txtrate") > 0)
                      {
                          Rate = GridRow.cells(child1).childNodes(0).value;

                      }

                      if (GridRow.cells(child1).childNodes(0).id.indexOf("txttotal") > 0)
                       {
                           GridRow.cells(child1).childNodes(0).value = Qty * Rate;
                      }
                  }

             }
         }
Posted
Updated 17-Jan-14 5:15am
v2

1 solution

Try like this..


HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <script src="jquery.js.js"></script>
    <script type="text/javascript">

        var calc = function (txt) {

            var rowid = txt.id.split('_')[2];// GridView1_txtRate_0
            var Rate = parseFloat(document.getElementById('GridView1_txtRate_' + rowid).value);
            var Qty = parseFloat(document.getElementById('GridView1_txtQty_' + rowid).value);
            document.getElementById('GridView1_txtAmt_' + rowid).value = Rate * Qty;
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">

            <Columns>
                <asp:TemplateField HeaderText="Rate">
                    <ItemTemplate>
                        <asp:TextBox ID="txtRate" onblur="calc(this);" runat="server"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Qty">
                    <ItemTemplate>
                        <asp:TextBox ID="txtQty" onblur="calc(this);" runat="server"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Amt">
                    <ItemTemplate>
                        <asp:TextBox ID="txtAmt" runat="server"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>

            </Columns>
        </asp:GridView>
    </form>
</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