I have a node list of chechbox inputs
const searchSizeSelectionInputs = document.querySelectorAll(
".sizeHolderFilter > input")
I have written a function to check whether or not any checkbox is checked or not, the function is
const activationChecker = ()=>{
if (
availabilityInStoreOptions[0].classList.contains("activeSortOptionSP") ||
availabilityInStoreOptions[1].classList.contains("activeSortOptionSP")
) {
isAvailabilityInStorActive = true;
}
if( !availabilityInStoreOptions[0].classList.contains("activeSortOptionSP") &&
!availabilityInStoreOptions[1].classList.contains("activeSortOptionSP")) {
isAvailabilityInStorActive = false;
}
searchSizeSelectionInputs.forEach(input => {
if (input.checked) {
isSizeInputChecked = true;
} else {
let isSizeInputChecked = false;
}
});
searchColorSelectionInputs.forEach(input => {
if (input.checked) {
isColorInputChecked = true;
} else {
let isColorInputChecked = false;
}
});
};
the thing is, when I check the result of isSizeInputChecked or isColorInputChecked it gives me faulty answers, for example when I check the checkbox it gives me true and when I uncheck the checkbox it still gives me true, I tested the same code on one single object and it works beautifully,I believe I do have a problem on doing this on a node list. This must be the wrong way:
searchSizeSelectionInputs.forEach(input => {
if (input.checked) {
isSizeInputChecked = true;
} else {
let isSizeInputChecked = false;
}
How can I check if any checkbox is checked or not any of them is checked?
leton theif (input.checked) { isSizeInputChecked = true;...test, is it a global variable while in the other case it is a local variable? it's really not clear