Demo: Limit Checkboxes with getElementsByName()

This version keeps the same three-selection limit but collects the group with getElementsByName().

0 of 3 selected.

Core JavaScript Top ↑

const boxes = [...document.getElementsByName("ckb")];
const limit = 3;
boxes.forEach((box) => {
  box.addEventListener("change", () => {
    const selected = boxes.filter((item) => item.checked);
    if (selected.length > limit) {
      box.checked = false;
    }
  });
});

getElementsByName() tutorial

Checkbox limit tutorial Value-sum demo Count-limit selector demo

Limit checkbox selection using a named group



Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer