I have a form with several checkboxes. I have three categories of checkboxes in the form. I need to limit to a max of three checkboxes per category.
I used
This is a newbie code with javascript. It's like working...hardly... I call this function on each input. But there is surely a way to call this function one time. It's working but uncheking a random checkbox from thoses who call it.
Education
Religions
News
function just2cat()
{
var allInp = document.getElementsByTagName('input');
const MAX_CHECK_ = 2; /*How many checkbox could be checked*/
var nbChk =0;
for(var i= 0; i MAX_CHECK_)
{
alert("At most 2 categories can be chosen");
allInp[i].checked=false; /* try to Unchek the current checkbox :'( */
}
}
}
}