limit checkbox selection javascript
// Limit/fix max number of items user can select via checkbox
var checks = document.querySelectorAll(".selected_products");
var max = 2;
for (var i = 0; i < checks.length; i++)
checks[i].onclick = selectiveCheck;
function selectiveCheck(event) {
var checkedChecks = document.querySelectorAll(".selected_products:checked");
if (checkedChecks.length >= max + 1){
alert("Maximum Items Selected")
return false;
}
}