Get check box value

Get check box value

YukozashiYukozashi Posts: 2Questions: 1Answers: 0
edited July 2015 in Free community support

Hello,

This similar question may have been asked several times in this forum. I'm trying to get the checked box value and submit the value. However, the submitted value only takes the current viewed pagination.
Currently, I'm using a bootstrap3 advance datatable based on this datatable which I'm guessing is the culprit. I've tried the JS based on the examples on this site, to no avail. Kindly point me toward the correct solution.

http://debug.datatables.net/obuhuq

The table is populated from server data

<table class="display table table-bordered table-striped" id="dynamic-table-4">
                        <thead>
                        <tr>
                            <th></th>
                            <th>Name</th>
                            <th>IC No. / Passport No.</th>
                            <th>Phone Number</th>
                            <th>Contractor Company</th>
                            
                        </tr>
                        </thead>
                         <tbody>
        <?php
                // $sql  = "SELECT compName , regTelco FROM ptw_users WHERE type = 'Contractor' ";
                // $rs = $conn->query($sql);
            
                // $num = 1;
                // $i = 0 ; 
                // $row = $rs->fetch_assoc() ;    

                // $a = unserialize($row['regTelco']) ;

            $sqlWork  = "SELECT a.*, b.compName FROM ptw_worker a INNER JOIN ptw_users b ON a.`compName`=b.`compName` WHERE a.`status2` = 'Approved' AND b.`regTelco` LIKE '%$comp%' GROUP BY workerID ";

                    
            $rswork = $conn->query($sqlWork);
            
            $j = 1 ;        
            while($rowWork = $rswork->fetch_array())
            {
        ?>                
                            <tr>
                                <td><input type="checkbox" name="cbWorker[]" value="<?php echo $rowWork["workerID"] ?>"></td>
                                <td><?php echo $rowWork["fullname"] ;?></td>
                                <td><?php echo $rowWork["icNo"] ;?></td>
                                <td><?php echo $rowWork["phoneNo"] ;?></td>
                                <td><?php echo $rowWork["compName"] ;?></td>
                                
                            </tr>    
         <?php
               
               $j++ ;
            }//close while
        ?>                      
                        </tbody>
                        </table>

The fnGetNodes

   $(document).ready(function() {
        $('#form').submit( function() {
            var sData = $('input[type="checkbox"]', oTable.fnGetNodes()).serialize();
            alert( 'The following data would have been submitted to the server: \n\n'+sData );
            return false;
        });

        oTable = $('#dynamic-table-4').dataTable();
    });

Answers

  • YukozashiYukozashi Posts: 2Questions: 1Answers: 0

    Okay, so I finally get the code to working, and successfully mark the checkboxes in each paginated page. However, due to the checkbox value populated from server, the output comes weird. It should display value such as 87;89 however the value comes out such as cbWorker%5B%5D=87&cbWorker%5B%5D=89

This discussion has been closed.