Link to home
Start Free TrialLog in
Avatar of sherbug1015
sherbug1015Flag for United States of America

asked on

Disable and Enable a Text Box

I have a textbox and a checkbox.  As long as the checkbox is not checked the textbox should be disabled.  

Due to the 3rd party framework I am using, I can't just simply use the codebehind.  I will need to script this.  I have written this jquery script that disables OK, but will not enable when the box is checked.  Can someone help me with what I'm doing wrong.    

$(document).ready(function () {
        $('#CheckBox1').click(function () {
            if ($(this).is(":checked"))

            $("TextBox1").attr("disabled", "enabled");

            else
                $("#TextBox1").attr("disabled", "disabled");

           
        });
    });

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And I think its just a simple typo:
you missed the # for the ID selector in the first if case.
Avatar of sherbug1015

ASKER

Perfect.  Thanks.
Avatar of dserubiri
dserubiri

This could also be another way
$(function(){
$("#CheckBox1").click({
if(this.ckecked){
$("#TextBox1").prop("disabled",false)
}
else{
$("#TextBox1").prop("disabled",true)
}
});
});