dimanche 30 décembre 2018

How to count number of checkboxes on open object in view?

I am trying to count the number of checkbox elements on the current panel I am on. What is happening is that I have checkboxes on 4 panels, on each panel there are checkboxes. Only one panel can be open at a time. When I do a count of checkboxes, I am getting the total of all the checkboxes in my app and not the number on the panel I am showing.

I have tried specifically telling the code that this is the window open var a = angular.element(document.querySelector('[widget-id="popup-1"] div')).scope().$parent.me.visible
but to no avail,

I am not sure how to tell the code that this is the panel that is open, count checkboxes on it only.

I am trying to count the number of boxes, then compare checked boxes and if num = checked, then I will continue on.

$scope.checkNum = function() {
 // var a = angular.element(document.querySelector('[widget-id="popup-1"] 
  div')).scope().$parent.me.visible
var inputs = document.getElementsByTagName("input");
//or document.forms[0].elements;
var cbs = [];
//will contain all checkboxes
var checked = [];
//will contain all checked checkboxes
  for (var i = 0; i < inputs.length; i++) {

  if (inputs[i].type == "checkbox") {
    cbs.push(inputs[i]);
    if (inputs[i].checked) {
      checked.push(inputs[i]);
    }

}
}
 var nbCbs = cbs.length;
 //number of checkboxes
 var nbChecked = checked.length;
   //number of checked checkboxes
    alert("# checkboxes = " + nbCbs + "\n" +  "# checked checkboxes = " + 
    nbChecked);
    console.log(" # checked checkboxes = " + nbChecked);
}




Aucun commentaire:

Enregistrer un commentaire