Enable button on checkbox checked
HTML
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
<table class="table table-bordered">
<tr>
<th><label><input type="checkbox" class="form-check-input" id="checkall" value="b" /> All</label></th>
<th>Product</th>
<th>Cost</th>
</tr>
<tr>
<td><input type="checkbox" class="form-check-input inv" name="bill" value="b1" /> 1</td>
<td>Unit 1</td>
<td>$10</td>
</tr>
<tr>
<td><input type="checkbox" class="form-check-input inv" name="bill" value="b2" /> 2</td>
<td>Unit 1</td>
<td>$8</td>
</tr>
<tr>
<td><input type="checkbox" class="form-check-input inv" name="bill" value="b3" /> 3</td>
<td>Unit 1</td>
<td>$20</td>
</tr>
</table>
<button type="submit" class="btn btn-primary btn-lg float-end" disabled>Submit</button>
JavaScript
$(function() {
$('#checkall').change(function() {
$('.inv').prop('checked', this.checked);
$('button[type="submit"]').removeAttr('disabled');
});
$('.form-check-input').change(function() {
if ($('.inv:checked').length == $('.inv').length) {
$('#checkall').prop('checked', true);
$('button[type="submit"]').removeAttr('disabled');
} else {
$('#checkall').prop('checked', false);
$('button[type="submit"]').attr('disabled', 'disabled');
}
});
});