The end code was mostly what I started with but I changed the addEventListener to click and it worked well:
function getSelectedCheckboxValues(name) {
const checkboxes = document.querySelectorAll(<code>input[name="${name}"]:checked</code>);
let values = [];
checkboxes.forEach((checkbox) => {
values.push(checkbox.value);
});
return values;
}
document.body.addEventListener('click', function (e) {
console.log(getSelectedCheckboxValues('colors-check'));
});
-
This reply was modified 5 years, 9 months ago by bcworkz. Reason: code fixed