vendredi 7 juin 2019

Retrieve parent child checked values as comma separated

I am developing application to select the role based menu. In that, I have parent-child check box and I want to retrieve checkbox checked value as 1, 1.1, 1.2, 2, 3 but current Jquery return as 1, 1, 2, 2, 3.

I have googled many things and implemented few too but there is no idea for parent child cheked values selection.

HTML

<ul>
  <li><input class="check_box" type="checkbox" value="1">Upload
    <ul>
      <li><input class="check_box" type="checkbox" value="1">Large </li>
      <li><input class="check_box" type="checkbox" value="2">Small </li>
    </ul>
  </li>
  <li><input class="check_box" type="checkbox" value="2">Move</li>
  <li><input class="check_box" type="checkbox" value="3">Producs</li>
  <li><input class="check_box" type="checkbox" value="5">User</li>
</ul>

Jquery

$('.check_box:checked').map(function () { return this.value; }).get().join(',')

Checkbox Selection

enter image description here

Current output

1, 1, 2, 2, 3

Expected Output

1, 1.1, 1.2, 2, 3

Please help me out guys.




Aucun commentaire:

Enregistrer un commentaire