JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<input type="checkbox" name="marque[1]" onclick="count_chkBox(this);" checked="v" />
<input type="checkbox" name="marque[2]" onclick="count_chkBox(this);" checked="checked" />
<input type="checkbox" name="marque[3]" onclick="count_chkBox(this);" />
<input type="checkbox" name="marque[52]" onclick="count_chkBox(this);" />
</form>
JavaScript
function count_chkBox(input) {
var form = input.form; //on recupere le formulaire
var nbchecked = 0;
var dbEl = form.elements; //recupere tous les elements du form
for (i = 0; i < dbEl.length; i++) {
var el = dbEl[i];
if (el.type == "checkbox" && el.name.match(/marque/) && el.checked) {
nbchecked++
}
}
if (nbchecked > 2) // ici je mets 2 mais c'est pour la demo
{
input.checked = false;
alert("message alerte");
}
}