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

Updating selected RadTextBox base on other textbox with Javascript

1 Answer 137 Views
Input
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 12 Jan 2009, 06:41 PM
Hello, I have a radgrid. Have one column of Radtextboxs each of their values are based on another column of radtextboxes. For example,
the value of radtextbox in row 1 column B (txt_result)= value of radtextbox in row 1 column A (txt_original)* 2. That is, whenever the user type 2 in txt_original, txt_result will automatically update its value to 4. I want to achieve this by using Javascript before I submit everything in the grid to the server.

Any help is appreciated!

Thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Jan 2009, 08:02 AM
Hi Vincent,

Try the following code snippet to achieve the desired scenario.

CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        RadTextBox txtbx1 = (RadTextBox)item["TempCol1"].FindControl("RadTextBox1"); 
        RadTextBox txtbx2 = (RadTextBox)item["TempCol2"].FindControl("RadTextBox2"); 
        txtbx1.Attributes.Add("OnBlur""return Change('" + txtbx1.ClientID + "','" + txtbx2.ClientID + "');"); 
    } 

JavaScript:
 <script type="text/javascript"
function Change(txtbx1,txtbx2) 
 { 
   var txtbx1=document.getElementById(txtbx1); 
   var txtbx2=document.getElementById(txtbx2);   
   txtbx2.value=txtbx1.value*2; 
</script> 

Thanks,
Shinu.
Tags
Input
Asked by
Vincent
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or