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

javascript to disable textbox when radcombox is selected

3 Answers 96 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vasya Ivanov
Top achievements
Rank 1
Vasya Ivanov asked on 05 May 2010, 09:36 PM
Hello,
I have RadComBox and RadTextBox.When radcombox contain value I need to disable radtextbox.The following is my code but not working:

 

<telerik:RadComboBox ID="ddlLocation" runat="server" Width="125px" Font-Size="Small" AutoPostBack="false" onchanged="JavaScript: return DisableBox();">

 

 

</telerik:RadComboBox>

 

 

</td>

 

 

<td>

 

 

 

 

<telerik:RadTextBox ID="LocTextBox" runat="server" Width="100px" MaxLength="4" ToolTip="Please enter 4 char Location" AutoPostBack="false">

 

 

</telerik:RadTextBox>

 

 

</td>

 

function

 

DisableBox()

 

{

 

 

 

var TextBox = $find("<%=LocTextBox.ClientID %>");

 

 

var Location = $find("<%=ddlLocation.ClientID %>");

 

 

if(Location.length > 0)

 

{

 

 

 

TextBox.disable();

 

 

return false;

 

}
}

Please help to resolve this issue.
Thanks so much

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 06 May 2010, 07:57 AM
Hello Vasya,

You can try the following approach in order to achieve the required.

ASPX:
 
<telerik:RadComboBox ID="ddlLocation" runat="server" Width="125px" Font-Size="Small" 
    AutoPostBack="false" OnClientSelectedIndexChanged="DisableBox"
    <Items> 
        <telerik:RadComboBoxItem Text="" Value="1" /> 
        <telerik:RadComboBoxItem Text="Item2" Value="2" /> 
    </Items> 
</telerik:RadComboBox> 
<telerik:RadTextBox ID="LocTextBox" runat="server" Width="100px" MaxLength="4" ToolTip="Please enter 4 char Location" 
       AutoPostBack="false"
</telerik:RadTextBox> 


JavaScript:
 
<script type="text/javascript"
    function DisableBox() { 
        var TextBox = $find("<%=LocTextBox.ClientID %>"); 
        var Location = $find("<%=ddlLocation.ClientID %>"); if (Location.get_text().length > 0) { 
            TextBox.disable(); 
        } 
        else { 
            TextBox.enable(); 
        } 
    } 
</script> 


Cheers,
Princy.
0
Jesse
Top achievements
Rank 1
answered on 24 Jul 2014, 01:45 PM
Hello, I know this post is a little old but it still helped me out. I was having trouble disabling my textbox based on the selection on a combobox. I used the code you provided and it worked. My problem now is that the text that is within the textbox does not get erased when a different selection is made. So my question is, is there a way to modify the code you provided to erase the text with the text box when the text box becomes disabled? Any help would be great!
0
Princy
Top achievements
Rank 1
answered on 25 Jul 2014, 02:39 AM
Hi Jesse,

Please modify the JavaScript as follows to clear the text of a disabled TextBox.

JavaScript:
function DisableBox() {
    var TextBox = $find("<%=LocTextBox.ClientID %>");
    var Location = $find("<%=ddlLocation.ClientID %>"); if (Location.get_text().length > 0) {
        TextBox.clear();
        TextBox.disable();
    }
    else {
        TextBox.enable();
    }
}

Thanks,
Princy.
Tags
General Discussions
Asked by
Vasya Ivanov
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Jesse
Top achievements
Rank 1
Share this question
or