This is a migrated thread and some comments may be shown as answers.

How to traverse collection of RadNumericTextBoxes inside ASP Table?

1 Answer 29 Views
Input
This is a migrated thread and some comments may be shown as answers.
Zinoviy Margovskiy
Top achievements
Rank 1
Zinoviy Margovskiy asked on 23 Oct 2009, 03:19 PM
Hi telerik,

I have an ASP Table with collection of RadNumericTextBoxes inside it. like this:
<asp:Table ID="tblMatrix" runat="server" CellSpacing="3" CellPadding="3">
         <asp:TableRow runat="server" ID="tblBodyRow_1">
                   <asp:TableCell runat="server" ID="tblBodyCell_R1_C2" Width="75px">
                            <telerik:RadNumericTextBox ID="txtQty_R1_C2" runat="server" Skin="AsiSkin" EnableEmbeddedSkins="False"
                                                                      Width="75px" Value="0">
                                <NumberFormat AllowRounding="false" KeepNotRoundedValue="true" DecimalDigits="0" />
                            </telerik:RadNumericTextBox>
                        </asp:TableCell>
                          .................. other cells
         </asp:TableRow >
         ................ other rows
</asp:Table >

on blur event of each text box I need to calculate total of all values in all text boxes. How do I do it in javascript?
Currently I have an OnBlure event where I traverse all textboxes inside table trying to calc. the sum... however it looks like the rendered
RadNumericTextBox consists of more then one html input control and the value of the visible control is not numeric...  Here is my code:
       ///////////////////////// =========== OnBlur Events =========== ////////////////////////////////// 
        function QtyTxt_OnBlur()  
        {             
            var cntrlMtrxTable = $get('<%= tblMatrix.ClientID %>');             
            if (cntrlMtrxTable)  
            { 
                CalculateMatrixTotals(cntrlMtrxTable); 
            } 
        } 
 
        /////////////////////////////////// UTILITIES //////////////////////////////////////// 
         
        ////////////////////////////////////////////////////////////////////////////////////// 
        /// Name: CalculateMatrixTotals() 
        /// Function Type: Event 
        /// Parameters:          
        ///////////////////////////////////////////////////////////////////////////////////// 
        function CalculateMatrixTotals(cntrlMtrxTable)  
        {             
            var cntrlTotalUsed = $get('<%= txtTotalUsed.ClientID %>'); 
            var cntrlTotalLeft = $get('<%= txtTotalLeft.ClientID %>'); 
            var cntrlCurrentLITotalQty = $get('<%= hdnCurrentLITotalQty.ClientID %>'); 
            var sumOfMatrixQty = 0; 
 
            var myInputArray = cntrlMtrxTable.getElementsByTagName("INPUT"); 
            for (var i = 0; i < myInputArray.length; i++)  
            { 
                var currInput = myInputArray[i]; 
                if (currInput.type == "text" && currInput.style.visibility != 'hidden' && currInput.id.indexOf('txtQty_') >= 0)  
                { 
                    sumOfMatrixQty += currInput.value; 
                }               
            } 
 
            if (cntrlTotalUsed && cntrlTotalLeft && cntrlCurrentLITotalQty)  
            { 
                var LITotalQty = cntrlCurrentLITotalQty.value; 
                cntrlTotalUsed.value = sumOfMatrixQty; 
                cntrlTotalLeft.value = LITotalQty - sumOfMatrixQty; 
                alert('cntrlTotalUsed.value = ' + cntrlTotalUsed.value); 
                alert('cntrlTotalLeft.value = ' + cntrlTotalLeft.value) 
                alert('sumOfMatrixQty = ' + sumOfMatrixQty); 
            } 
        } 
         
    </script> 
 
</telerik:RadScriptBlock> 




1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 28 Oct 2009, 08:03 AM
Hi Zinoviy,

Thank you for contacting us and for your question.
To see more information along the lines of the requested functionality, please refer to the following example:

http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandinput/defaultcs.aspx?product=grid

Give the suggested approach a try and let me know how it goes and if any other questions arise, or you find that I am leaving something out.

Regards,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Input
Asked by
Zinoviy Margovskiy
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or