javascript - HTML form doesn't capture all the checkboxes from Bootstrap responsive table -


i have table displays results db. in last column have checkboxes , clicking submit button sending array of account_id's php file. works fine problem using bootstrap responsive table can show 10-100 results on each page , form captures results on current page. if check boxes on different pages , switch between them, still remain checked, though. here html:

<form action="compare.php" method="post"> <table class="table table-hover" id="datatables-example">      <thead>         <tr>             <th style="text-align:center;">account name</th>             <th style="text-align:center;">address</th>             <th style="text-align:center;">phone number</th>             <th style="text-align:center;">website</th>             <th style="text-align:center;">compare</th>         </tr>     </thead>     <tbody>                                         <?php          $result= mysql_query("select * accounts order account_name asc" ) or die (mysql_error());         while ($row= mysql_fetch_array ($result) ){                                          ?>         <tr>             <td class='clickable-row' data-href="select.php?id=<?php echo $row ['account_id'];?>"> <?php echo $row ['account_name'];?></td>             <td class='clickable-row' data-href="select.php?id=<?php echo $row ['account_id'];?>"> <?php echo $row ['address']; ?></td>             <td class='clickable-row' data-href="select.php?id=<?php echo $row ['account_id'];?>"> <?php echo $row ['phone_number']; ?></td>             <td class='clickable-row' data-href="select.php?id=<?php echo $row ['account_id'];?>"> <?php echo $row ['website']; ?></td>             <td> <input type="checkbox" name="checkboxvar[]" value="<?php echo $row ['account_id'];?>" /></td>         </tr>         <?php } ?>      </tbody> </table> <input class="btn btn-success" type="submit" value="compare" id="submit"> </form> 

i tried use jquery see if can capture checkboxes whole table, results same trying html form. script supposed capture them , make alert:

<button id="bt1">get</button>  <script>  $('#bt1').on('click', function () { //get checked checkboxes var checkedcheckboxes = $("#datatables-example :checkbox:checked"),     arr = [];  //for each checkbox (var = 0; < checkedcheckboxes.length; i++) {      //get checkbox     var checkbox = $(checkedcheckboxes[i]);      //get checkbox value     var checkboxvalue = checkbox.val();      //get siblings     var siblings = checkbox.parent().siblings();      //get values of siblings     var value1 = $(siblings[0]).text();     var value2 = $(siblings[1]).text();      arr.push(checkboxvalue + '-' + value1 + '/' + value2);      alert(checkboxvalue + '-' + value1 + '/' + value2); } });  </script> 

is there way it?

you can use datatables object:

$('input', otable.fngetnodes()).each(function () {   if($(this).is('checked')){     console.log($(this).val());   } }); 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -