How can I enable the textbox when the checkbox is check

1.6k Views Asked by At

How can I enable the textbox when the checkbox is checked in JavaScript:

Can someone please show me how to do it correct please! this is my code:

 function checkLevelZone() {
            var txtOffSite = $find("<%=txtOffSite.ClientID %>");
            var checkbox = $find("<%=OffSiteCheck.ClientID %>");
            if (checkbox.checked) {
                txtOffSite.removeAttribute('Enabled');
                } else {
                txtOffSite.disabled = true;
               }

            }

asp:

<telerik:RadButton ID="OffSiteCheck" runat="server" ToggleType="CheckBox" ButtonType="ToggleButton"  OnClientCheckedChanged="checkLevelZone"  Skin="Windows7"></telerik:RadButton>
                                <telerik:RadTextBox ID="txtOffSite" runat="server" Enabled="false"> </telerik:RadTextBox>
4

There are 4 best solutions below

0
On

Use this:

txtOffSite.disabled = !checkbox.checked;
8
On

Give it a try

function checkLevelZone() {
    var checkbox = $("#<%=OffSiteCheck.ClientID %>");
    if (checkbox.checked) {
        $("#<%=txtOffSite.ClientID %>").removeAttribute('disabled');
    } else {
        $("#<%=txtOffSite.ClientID %>").attr("disabled", "disabled");
    }
}
0
On

Since you used OnClientCheckedChanged, your function signature is incorrect.

function checkLevelZone(sender, args) {  
    if (args.get_checked()) { // Most rad controls use .set_enabled(true), the RadTextBox is different.
        $find('<%= txtOffSite.ClientID%>').enable();  // $find() works, $() doesn't always work.
    }
    else {    
        $find('<%= txtOffSite.ClientID%>').disable();
    }
}

Online documentation for RadNumericTextBox, most of which applies to RadTextBox

0
On

It's working for me....

$("#checkBoxId").change(function() {

$("#textBoxId" />").prop("disabled", !$(this).is(':checked'));

}) ;