How do I disabled textbox if checkbox is checked. I've got a few textboxes and checkboxes next to each other.
HTML:
<form id="form">
<input type="checkbox" name="deposit_checked"> <input type="text" name="deposit_value">
<input type="checkbox" name="booking_checked"> <input type="text" name="booking_value">
<input type="checkbox" name="referral_checked"> <input type="text" name="referral_value">
</form>
I can do it individually with code below:
$("input[name=deposit_checked]").change(function(){
if( $("input[name=deposit_checked]").is(":checked") ) {
$("input[name=deposit_value]").attr("disabled", false);
} else {
$("input[name=deposit_value]").attr("disabled", true);
}
})
to save time, I tried using .each() and .next() function but no luck:
$("#form input[type=checkbox]").each(function() {
$(this).change(function(){
if( $(this).is(":checked") ) {
$(this).next().attr("disabled", false);
} else {
$(this).next().attr("disabled", true);
}
})
})