javascript to disable textbox when radcombox is selected

4 posts, 0 answers
  1. Vasya Ivanov
    Vasya Ivanov avatar
    78 posts
    Member since:
    Apr 2010

    Posted 05 May 2010 Link to this post

    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

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 May 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jesse
    Jesse avatar
    3 posts
    Member since:
    Jun 2014

    Posted 24 Jul 2014 in reply to Princy Link to this post

    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!
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jul 2014 in reply to Jesse Link to this post

    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.
Back to Top