Javascript: Check if any checkbox is checked

If you want to check if any checkbox is selected, but checkboxes have all the same name and are so part of an array, here is an example of how to do:

anychecked = false;
for(var i=0; i< document.forms.form1["mycheckboxes"].length;i++) {
  if(document.forms.form1["mycheckboxes"][i].checked == true) {
    anychecked = true;
    break;
  }
}
if(anychecked)
  alert('At least one checkbox is checked');

Questions or comments?

Join the discussion on Discord, ask a question or share your experience.

Discuss on Discord
  1. JSBricks game screen with bricks, paddle and ballProjects: JSBricks, an arkanoid clone in javascript
  2. Javascript: Decode HTML entities
  3. 20201212_174208DIY volumio driven audiophile DAC and CD player