Hi everybody!
I’m running a script, that checks 15 checkboxes in a form and if one is checked it’s name joins a list.
<script>
document.querySelector('button#listgen').onclick = function () {
const checkboxes = document.getElementsByName ("items");
let checkitem = "";
checkboxes.forEach ((item) => {
if (item.checked === true) {
checkitem += item.value + " ";
}
})
if (checkitem === "") {
document.querySelector('.liste').innerHTML = "";
} else {
document.querySelector('.liste').innerHTML = "Items are: "+checkitem;
}
}
</script>
The script is activated by a button. How must this be changed, that no more “generate”-button is needed and that it works “onchange” (not “onclick”) so that the resulting list is automatically generated depending on which checkbox is checked or unchecked?