You can do something like this:
function anyCheckboxesChecked() { var inputs = document.getElementsByTagName('input'); for (var i = 0; i < inputs.length; ++i) { if (inputs[i].type === "checkbox" && inputs[i].checked) return true; } return false; }
Then you can call this function from the submit handler
if (!anyCheckboxesChecked()) { alert("Please check one of the appealing checkboxes on the page"); return false; }
If your page is more complex than it means (for example, if there are several forms), you must first find the appropriate form and call .getElementsByTagName() from this point instead of document .
source share