Click here to Skip to main content
14,735,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I need sum of Repeater textbox values in repeater footer. I have tried with JQuery key press event, it executed fine at first time.. When i click save/cancel button event. the sum of values is not execute. how to resolve...


Thanks & regards,
Vivek .R

What I have tried:

<script type="text/javascript">      
            $(document).ready(function () {
                //Iterate through each Textbox and add keyup event handler
                $(".clsTxtToCalculate").each(function () {
                    $(this).keyup(function () {
                        //Initialize total to 0
                        var total = 0;
                        $(".clsTxtToCalculate").each(function () {
                            // Sum only if the text entered is number and greater than 0
                            if (!isNaN(this.value) && this.value.length != 0) {
                                total += parseFloat(this.value);
                            }
                        });
                        //Assign the total to label
                        //.toFixed() method will roundoff the final sum to 2 decimal places
                        $('#<%=lblAcFees.ClientID %>').html(total.toFixed(2));
                    });
                });
            });           
    </script>

<itemtemplate>
        <tr>

             <td style="display:none;"><asp:Label runat="server" ID="lblFeesCode" text='<%# Eval("FeesCode") %>' /> </td>
            <td><asp:Label runat="server" ID="lblFees" text='<%# Eval("Fees") %>' /></td>
            <td> <asp:TextBox ID="txtFeesAmt" runat="server" Width="100px" Text="0" onkeypress="return isNumberDotKey(event);" CssClass="clsTxtToCalculate" style="text-align:right;">
            <asp:RequiredFieldValidator ID="rfvFeesAmt" runat="server" ForeColor="Red" controltovalidate="txtFeesAmt" errormessage="*" ValidationGroup="vg1" />
            </td>

        </tr>
        </itemtemplate>
Posted
v6
Comments
[no name] 15-Feb-16 1:36am
   
It is executing javascript code, not giving correct result or not executing javascript code.

It would be better if you can provide part of HTML code for repeater to see how it structured.
Vivek.anand34 15-Feb-16 2:18am
   
above tat code 'txtFeesAmt' enter the amount. the total values is to be display in footer.
Vivek.anand34 15-Feb-16 2:15am
   
i have updated question.. but its not properly displaying.. so part of Item template tag.
   
That is because you are calculating only on key up not on load.
Vivek.anand34 15-Feb-16 3:14am
   
Keyup means keyboard keyup ryt.. But, y 2nd time its not execute.. i no need on load event.. without pageload i need, thats why i choose java script code.
   
Document load is also present on JavaScript. That's why I said. Anyway, I don't understand the problem. I am confused.

Do you need to recalculate the total and show after save?
Vivek.anand34 15-Feb-16 5:50am
   
Actually, when i open screen and Enter the value then click save, its works fine. Enter the next record the calculation is not working..
   
Did you debug and see?
Vivek.anand34 15-Feb-16 6:34am
   
no. how to debug it..
   
Use developer tool F12 in browser. Else write "debugger;" inside code wherever you want to put a break point.

1 solution

<script type="text/javascript">
       $(document).ready(function () {

           var totalText = $('#total');

           var repeater = $("#kt_repeater_1");
//Iterate through each repeater Textbox and add change event handler
           repeater.on("change", ".input", function () {
               var total = 0;
               repeater.find(".input").each(function () {
                   if (!isNaN(this.value) && this.value.length != 0) {
                       total += parseFloat(this.value);
                   }
                   totalText.val(total);
               });
           });

       });
   

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