Can anyone please tell me how to disable a textbox, if a checkbox is checked, and enable textbox if the checkbox is not checked?
Disable the TextBox by adding the e-disabled to the input parent element and set disabled attribute to the input element.
How do I make a checkbox readonly in JavaScript? A checkbox HTML element doesn't have a "readonly" property. Consequently, the only way to make a checkbox appear to be "readonly" is to disable the control.
Use the preventDefault() method to stop the default behavior of a particular element.
Put this in the checkbox:
onclick="document.getElementById('IdOfTheTextbox').disabled=this.checked;"
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With