earwig75
asked on
How can I enable / disable a text box with a checkbox
I have a text box that I'd like to disable when a checkbox is checked. Can someone offer sample code that would disable the input box when the checkbox is checked, and then enable it when it's unchecked? I can use javascript or jquery.
Thank you.
Thank you.
<input name="myInput" id="myInput" maxLength="10" type="text" />
<input name="myCheckBox" id="myCheckBox" type="checkbox" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this ;)
<input name="myInput" id="myInput" maxLength="10" type="text" />
<input name="myCheckBox" id="myCheckBox" type="checkbox" onchange="javascript:changed(this);" />
<script>
var txtField = document.getElementById('myInput');
function changed(el){
if(el.checked){
alert('Alert content goes here...');
}
txtField.disabled = el.checked;
}
</script>
ASKER