I have a table with a datagrid (checkboxes and labels in each row). I want to disable a button by checking if a label is "Forbidden". The user can check multiple checkboxes. So my question is how do I get all the checked checkboxes and then check if the label in each selected row is of value "Forbidden" so I can disable the button.
I tried something like this:
$(function() {
checkboxes = document.querySelectorAll('[id=checkId]');
var validateBtn = $('button[name="btnVal"]');
checkboxes.forEach((cb) => {
cb.addEventListener('change', checkStatus);
});
function checkStatus() {
//to-do
// if ($(this).is(":checked")) {
var label = document.getElementById('statusLabel');
if (label.textContent == "Forbidden") {
validateBtn.prop('disabled', true);
}
}
});
The table looks like this:enter image description here In this case the button should be disabled as we have selected a forbidden status.
You can check the property of the checkbox and disable the button according to this will be:
$('#id_of_your_checkbox').click(function() {
if ($(this).is(':checked')) {
$('#id_of_your_button').attr('disabled', 'disabled');
} else {
$('#id_of_your_button').removeAttr('disabled');
}
});