Click here to Skip to main content
14,577,432 members
Rate this:
Please Sign up or sign in to vote.
See more:
<asp:TableRow runat="server" BackColor="#92cc91">
                            <asp:TableCell  runat="server" ><asp:Label ID="TimeCode1" runat="server" width="50px" Text="1" BackColor="Transparent" BorderStyle="None"></asp:Label>
                            </asp:TableCell>
                            <asp:TableCell runat="server" ><asp:TextBox ID="TbDay11" CssClass="myTC"  style="text-align: center" runat="server" width="75px" AutoPostBack="True" ></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server" ><asp:TextBox   runat="server" ID="TbDay21" CssClass="myTC" style="text-align: center; width: 75px;" AutoPostBack="True"></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server" ><asp:TextBox ID="TbDay31"  CssClass="myTC" runat="server" style="text-align: center" width="75px"   AutoPostBack="True"></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server" ><asp:TextBox ID="TbDay41" CssClass="myTC" runat="server"  style="text-align: center" width="75px" AutoPostBack="True" ></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server" ><asp:TextBox ID="TbDay51" CssClass="myTC" runat="server"   style="text-align: center" width="75px" AutoPostBack="True" ></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server" ><asp:TextBox ID="TbDay61" CssClass="myTC" runat="server"   style="text-align: center" width="75px" AutoPostBack="True" ></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server"><asp:TextBox ID="TbTotalHrs1" CssClass="corners totalRow" runat="server"  style="text-align: center" width="75px" AutoPostBack="True" ReadOnly="True"></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server"><asp:TextBox ID="TbProgHrs1" CssClass="corners" runat="server"  style="text-align: center" width="75px" AutoPostBack="True" ReadOnly="True"></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server"><asp:TextBox ID="TbDelta1" CssClass="corners" runat="server" style="text-align: center" width="75px" AutoPostBack="True" ReadOnly="True"></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server"><asp:TextBox ID="TbFixed1" CssClass="corners" runat="server"  style="text-align: center" width="75px" AutoPostBack="True" ReadOnly="True"></asp:TextBox>
                            </asp:TableCell>
                        </asp:TableRow>

<pre><script type="text/javascript">
    $(".myTC").focusout(function () {
        $('tr').each(function () {
            //the value of sum needs to be reset for each row, so it has to be set inside the row loop
            var sum = 0
            //find the TC elements in the current row and sum it 
            $(this).find('.TC').each(function () {
                var tc = $(this).text();
                if (!isNaN(tc) && tc.length !== 0) {
                    sum += parseFloat(tc);
                }
            });
            //set the value of currents rows sum to the TotalHrs element in the current row
            $('.TbTotalHrs1', this).html(sum);
        });
        });
       
    
</script>



What I have tried:

Hello guys, need a little help here, trying to sum up the TbDay11,TbDay21,TbDay31... etc.. and put the Total in TbTotalHrs1 using jquery as i want this to happen without refreshing the whole page.
Table is has ID of 'myPostTable' and is wrapped in an UpdatePanel if that matters.
I'm new to jquery and struggling to figure this out.. any help would be appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100