Toggle Disabled Attribute on Input Based on Checkbox in jQuery
forms, javascript, jquery
Solution
You have to assign id to checkbox to bind the click to particular checkbox,
Live Demo
<input type="checkbox" id="chk">
$("#chk").click(function(){
$("#disabledInput").attr('disabled', !this.checked)
});
Problem
I have a checkbox that is unchecked by default and a disabled input by default. ``` <label class="checkbox span3"><input type="checkbox"> I am a full-time student.</label> <input class="inputIcon span3" id="disabledInput" type="text" placeholder="Enter School Name" disabled> ``` I have full control over the class and id names and the site uses jQuery so can use that or plain javascript if needed. If a user checks the box, then the "disabled" attribute should be removed from the following input. If the user unchecks it should become disabled again. Found a several similar questions on StackOverflow but none seem to be this exact use case.