Click here to Skip to main content
15,867,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi all,

i have two HTML text boxes inside repeater. on text change of those text box i want to do sum and display in 3rd HTML text box using JQuery.

how can i achieve it?

Thanks,
KK
Posted
Updated 4-Jun-21 1:36am

1 solution

Below is sample code

ASPX code

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <div>
                <asp:TextBox ID="TextBox1" runat="server" Text=0 />
                <asp:TextBox ID="TextBox2" runat="server" Text=0 />
                <asp:TextBox ID="TextBox3" runat="server" />
            </div>
        </ItemTemplate>
    </asp:Repeater>
    </div>

    <script>

     function GetTotalAmount(obj){
          var txtbox1id = obj.id.replace('TextBox2','TextBox1');
          var txtbox2id = obj.id.replace('TextBox1','TextBox2');
          var txtbox3id = obj.id.replace('TextBox1','TextBox3').replace('TextBox2','TextBox3');
            var total =parseFloat($('#'+ txtbox1id).val()) +parseFloat($('#'+txtbox2id).val());
            $('#' + txtbox3id).val(total);
           }


      $(document).ready(function() {
            $("input[id*=TextBox1]").each(function() {
            $(this).change(function() {
              GetTotalAmount(this);
            });
          });

            $("input[id*=TextBox2]").each(function() {
            $(this).change(function() {
              GetTotalAmount(this);
            });
          });

    });

    </script>
    </form>
</body>
</html>
 
Share this answer
 
Comments
kk2014 25-May-13 9:27am    
hi,

i said html text boxes not asp.

but thanks for the reply.

thanks.

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