lundi 10 septembre 2018

Select All | Deselect All check boxes using a toggle button

I need to select all and deselect all check boxes on a button toggle.

here is the html code for check-boxes

<div class="accordion-header js-accordion-header">
<input type="checkbox" class="to-labelauty-icon labelauty" name="inputLableautyNoLabeledCheckbox" data-plugin="labelauty" data-label="false" id="labelauty-2" value="tc_Logout" aria-hidden="true" style="display: none;">
<label for="labelauty-2">
<span class="labelauty-unchecked-image"></span>
<span class="labelauty-checked-image"></span>
</label>  tc_Logout
</div>

when I select this check box aria-checked="true" is automatically added to <label for="labelauty-2"> which output this

<label for="labelauty-1" aria-checked="true">
<span class="labelauty-unchecked-image"></span>
<span class="labelauty-checked-image"></span>
</label>

It changes the status to true or false when its checked and unchecked.

Now I have several check-boxes like this which needs to be checked or unchecked using a toggle button.

here is my html code for toggle button

<div class="toggle-wrap w-checkbox float-right">
  <input class="toggle-ticker w-checkbox-input" data-ix="toggle-switch" data-name="Toggle Switch" id="Toggle-Switch" name="Toggle-Switch" type="checkboxtoggle" onclick="toggle()">
  <label class="toggle-label w-form-label" for="Toggle-Switch"></label>
  <div class="toggle">
    <div class="toggle-active">
      <div class="active-overlay"></div>
      <div class="top-line"></div>
      <div class="bottom-line"></div>
    </div>
  </div>
</div>

Here is my JS code which returns an error "prop is not defined"

function toggle(source) {
  checkboxes = document.getElementsByName('inputLableautyNoLabeledCheckbox');
  for (var i = 0, n = checkboxes.length; i < n; i++) {
    checkboxes[i].checked = source.checked;
  }
}

How can I achieve this using javascript or jquery




Aucun commentaire:

Enregistrer un commentaire