sum two textboxes inside radedit form template using javascript

2 posts, 0 answers
  1. Sumeet
    Sumeet avatar
    2 posts
    Member since:
    Oct 2015

    Posted 21 Oct 2015 Link to this post

    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;


     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

  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 23 Oct 2015 Link to this post

    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.

    Konstantin Dikov
    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
Back to Top