<input type="checkbox" name="ch_1" class="required"> checkbox 1 <br>
<input type="checkbox" name="ch_2" class="required"> checkbox 2 <br>
<input type="checkbox" name="ch_3" class="required"> checkbox 3 <br>
<input type="checkbox" name="ch_4" class="required"> checkbox 4 <br>
<input type="checkbox" name="ch_5" class="required"> checkbox 5 <br>
<button type="submit" id="submit">Submit</button>
let submit = document.querySelector('button')
submit.onclick = function() {
console.log('click');
let nodes = document.querySelectorAll('.required');
for (let i = 0; i < nodes.length; i++) {
if (!nodes[i].checked) {
alert("Нужно отметить всё");
break;
}
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.