mercredi 14 août 2019

Get only the value of checked dynamic checkboxes

I have the following checkboxes getting from database

while($result = mysqli_fetch_array($query)){
    $srNumber = $result['srNumber'];
    $oaName = $result['oaName'];
    echo '
        <td><input class="checkBoxes" type="checkbox" name="checkBoxArray[]" value="'.$oaName.'"></td>
        <td>'.$oaName.'</td>
        </tr>';
}

And have the following code to get the value of those checked checkboxes

< script >
  $(document).ready(function() {
    $(".checkBoxes").click(function() {
      if ($(this).is(":checked")) {
        var searchIDs = $(".checkBoxes").map(function() {
          return $(this).val();
        }).get();
        alert(searchIDs);
      }
    });
  }); 
< /script >

Problem

My problem is, it always getting value of all checkboxes no matter it is checked or not. May I know how to get only the checked boxes value?




Aucun commentaire:

Enregistrer un commentaire