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

sum two textboxes inside radedit form template using javascript

1 Answer 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sumeet
Top achievements
Rank 1
Sumeet asked on 21 Oct 2015, 08:32 AM

i tried that code without radgrid and is working fine

  <script type="text/javascript">
                                      function sum() {
                         var txtFirstNumberValue = document.getElementById('txt1').value;
                         var txtSecondNumberValue = document.getElementById('txt2').value;
                         var result = parseInt(txtFirstNumberValue) + parseInt(txtSecondNumberValue);
                         if (!isNaN(result)) {
                             document.getElementById('txt3').value = result;
                         }
                     }                                       
        </script>           

 

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not Page.ClientScript.IsStartupScriptRegistered("test")) Then
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "test", "sum();", True)
        End If
    End Sub

 

But my problem was that i'm working with radgrid editform template, i have same 3 text boxes inside radgrid editform template, how to implement the above scenario with radgrid editform template

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 23 Oct 2015, 02:13 PM
Hello Sumeet,

You have two options for achieving this requirement in the context of the edit item:

1) Handle the server-side OnItemDataBound event of the grid, get reference to the edit form item and the TextBox controls and calculate the sum on server-side. Detailed information for getting reference to controls on server-side could be found in the following help article:
2) The second approach would be to handle the client-side pageLoad event, get reference to the edit form item, find the elements generated for the TextBox controls and perform the calculation. For getting reference to standard controls (like TextBox, Label, etc.) you can use the $telerik.findElement(container, controlID) method, where the container in your scenario will be the form template. If you are using a control from our suite (a RadNumericTextBox for example) you will have to use $telerik.findControl(container, controlID) method instead and use the methods from the client-side API for retrieving and settings the values.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Sumeet
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or