2

This may be a duplicate question,

But still, I did not find the answer.

My requirement is :

How to get the table rows which are CHECKED.

Here is my issue's screenshot. enter image description here enter image description here

My checkbox name is 'check[]'

and the name of the select box is 'class[]',

and the form is posted to process.php.

How to get the value of 'class[]' where the checked boxes are checked so that I can then process with PHP-MYSQL?

My code is here:

<div class="col-md-5">
<form action="process.php" method="post">

<table class="table" id="table">
    <tr><th>Opt</th><th>Name</th><th>Next Class</th></tr>
    <? $q = $sdb->where('ac_CurClass',4)->get('tbl_accounts');
    foreach ($q as $r){ ?>
    <tr>
        <td><input type="checkbox" name="sel[]" class="checkbox small" value="<?=$r['ac_Id'];?>"></td>
        <td><?=ac_details($r['ac_Id'])->ac_Name;?></td>
        <td>
            <select class="form-control small" name="class[]">          
            <? $c = $sdb->where('c_Id',ac_details($r['ac_Id'])->ac_CurClass,">")->get("tbl_classes"); 
                foreach($c as $d) {?>
                <option value="<?=$d['c_Id'];?>"><?=$d['c_Name'];?></option>
            <? } ?></select>
        </td>
    </tr>
    <? } ?>
</table>
<button type="submit" class="btn btn-danger">Update</button>
</form>
</div>
Priyamanu
  • 183
  • 1
  • 3
  • 11

2 Answers2

2

Hope this code is help full for you

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<div class="col-md-5">
<form action="#" method="post">
<table class="table" id="table">
<thead><tr><th>Opt</th><th>Name</th><th>Next Class</th></tr></thead>
<tbody id="cont">
<tr>
    <td><input type="checkbox" name="sel[]" class="checkbox small" value="1"></td>
    <td>asass</td>
    <td>
        <select class="form-control small" name="class[]">          
        <option value="">Select option</option>
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
        </select>
    </td>
</tr>
<tr>
    <td><input type="checkbox" name="sel[]" class="checkbox small" value="2"></td>
    <td>asass</td>
    <td>
        <select class="form-control small" name="class[]">          
        <option value="">Select option</option>
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
        </select>
    </td>
</tr>
<tr>
    <td><input type="checkbox" name="sel[]" class="checkbox small" value="3"></td>
    <td>asass</td>
    <td>
        <select class="form-control small" name="class[]">          
        <option value="">Select option</option>
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
        </select>
    </td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-danger" id="submit">Update</button>
</form>
</div>
<script>
$(document).ready(function(){
$('#submit').click(function(){
    $("#cont input:checkbox:checked").map(function(){
        alert('Checkbox value - '+$(this).val()+' / Select Box value - '+$(this).parent().next().next('td').find('select').val());
        //alert('Select Box value - '+$(this).parent().next().next('td').find('select').val());
    });
});
});
</script>

After that you can pass a Ajax so that only checked rows post.

Avinash Sinha
  • 534
  • 3
  • 16
1

Try as follows

Post as form

<form action="process.php" method="post">

In process.php file

if($check[0]===true){
$nextclass1 = $_POST['list_box'];
}
if($check[1]===true){
$nextclass2= $_POST['list_box'];
}
Arshid KV
  • 9,631
  • 3
  • 35
  • 36