I have 15 check boxes in a form. This checkboxes are independent to eachother. I want a javascript function that makes, when user is selecting 2 checkboxes, the first checke
I created this CodePen off of John's answer, but I added the ability to uncheck all checkboxes.
HTML:
JavaScript:
function selectOnlyThis(id) {
for (var i = 1;i <= 4; i++){
if ("Check" + i === id && document.getElementById("Check" + i).checked === true){
document.getElementById("Check" + i).checked = true;
} else {
document.getElementById("Check" + i).checked = false;
}
}
}
https://codepen.io/thomasweld/pen/Pmaega?editors=1010