sherbug1015
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.
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");
});
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect. Thanks.
This could also be another way
$(function(){
$("#CheckBox1").click({
if(this.ckecked){
$("#TextBox1").prop("disab led",false )
}
else{
$("#TextBox1").prop("disab led",true)
}
});
});
$(function(){
$("#CheckBox1").click({
if(this.ckecked){
$("#TextBox1").prop("disab
}
else{
$("#TextBox1").prop("disab
}
});
});
you missed the # for the ID selector in the first if case.