1// Limit/fix max number of items user can select via checkbox
2
3var checks = document.querySelectorAll(".selected_products");
4var max = 2;
5for (var i = 0; i < checks.length; i++)
6 checks[i].onclick = selectiveCheck;
7
8function selectiveCheck(event) {
9 var checkedChecks = document.querySelectorAll(".selected_products:checked");
10 if (checkedChecks.length >= max + 1){
11 alert("Maximum Items Selected")
12 return false;
13 }
14}