I have a checkbox/select and want the select to be enabled when the checkbox is checked and disabled when unchecked.
<p>
<input id="option[21]" type="checkbox" name="checkbox[21]">
<select id="option[21]" name="select[21]" disabled><option value="">-</option><option value="1">Today</option><option value="2">Tomorrow</option></select>
</p>
<p>
<input id="option[22]" type="checkbox" name="checkbox[22]">
<select id="option[22]" name="select[22]" disabled><option value="">-</option><option value="1">Today</option><option value="2">Tomorrow</option></select>
</p>
When I run my code, it doesn't appear to select the dropdown correctly:
$(document).on('change', 'input[type=checkbox]', function(event) {
var selectId = event.target.id;
console.log(selectId);
if ($(this).is(':checked')) {
$(selectId).removeAttr('disabled');
} else {
$(selectId).prop( "disabled", true );
}
});