If any of the checkboxes are checked, I want to enable the button. Otherwise, if none are checked, I want to disable the button.
jQuery
$(document).ready(function() {
$('.check_list').change(function() {
if ($(".check_list input:checkbox:checked").length > 0){
$(".btn").attr('disabled','disabled');
} else {
$(".btn").removeAttr('disabled');
}
});
});
<script src="http://ift.tt/1oMJErh"></script>
<input type="checkbox" class="check_list" name="check_list[]" value="value1">
<input type="checkbox" class="check_list" name="check_list[]" value="value2">
<input type="checkbox" class="check_list" name="check_list[]" value="value3">
<input type="checkbox" class="check_list" name="check_list[]" value="value4">
<button class="btn" disabled> Button</button>
It works when I check the button. But when I uncheck everything it is still enabled. But it should be disabled
Aucun commentaire:
Enregistrer un commentaire