tags:

views:

1240

answers:

7

hi can any one please tell me how to disable textbox, if checkbox is checked and enable textbox if the checkbox is not checked

+1  A: 

Are you using "plain" JavaScript or some library (jQuery, prototype, ...)?

Jan Hančič
this should be a comment not an answer
jmein
I know, but I can't comment yet :(
Jan Hančič
at least not on other answers/questions that are not mine ...
Jan Hančič
+5  A: 

Put this in the checkbox:

onclick="document.getElementById('IdOfTheTextbox').disabled=this.checked;"
Guffa
+1 - I like the lack of a conditional.
James Black
A: 

Is pseudocode (not a lot of javascript experience):

OnCheckboxChanged(bool isChecked) {
    textbox.Enabled = !isChecked;
}
Greg D
A: 
function disableControl(controlId)
{
    document.getElementById(controlId).disabled = true;
}
James
+1  A: 

Using jQuery:

$("#checkbox").click(function(){
  $("#textbox").disabled = $(this).is(":checked");
});
Marius
+2  A: 
    <input type="text" id="textBox">
    <input type="checkbox" id="checkBox" onclick="enableDisable(this.checked, 'textBox')">
    <script language="javascript">
    function enableDisable(bEnable, textBoxID)
    {
         document.getElementById(textBoxID).disabled = !bEnable
    }
</script>
Kevin