Answers for "limit checkbox selection javascript"

1

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;
  }
}
Posted by: Guest on August-05-2021

Code answers related to "limit checkbox selection javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language