get all checked checkboxes in Javascript

If you could get all of the checked checkboxes utilizing Javascript, then you are able to do the next:

Choice 1 – In a single line

const checkedBoxes = doc.querySelectorAll('enter[name=mycheckboxes]:checked');

Choice 2 – One other one liner

const information = [...document.querySelectorAll('.mycheckboxes:checked')].map(e => e.worth);

Choice 3 – Create a helper operate

operate getCheckedBoxes(checkboxName) {
  var checkboxes = doc.getElementsByName(checkboxName);
  var checkboxesChecked = [];

  for (var i=0; i<checkboxes.size; i++) {
     if (checkboxes[i].checked) checkboxesChecked.push(checkboxes[i]);
  return checkboxesChecked.size > 0 ? checkboxesChecked : null;

Now you merely name the operate:

var checkedBoxes = getCheckedBoxes("mycheckboxes");
See also  Find out how to resolve AWS MediaPackage PackagingGroup Quota Restrict

Leave a Reply