I have jQuery to get multiple checkbox value.
You can refer for the demo here
The function for that jQuery is OK, when We tick the checkbox then We can see what We choose based on data-id after btnUpdate click.
But now I want to pass and store it to database using PHP by Ajax. So Example output,
1 -> read
1 -> update
2 -> update
Then save it to database on table:
ID | chkStatus
1 | read
1 | update
2 | update
Here is the HTML
<table>
<tr>
<th>Nama</th>
<th>Create</th>
<th>Read</th>
<th>Update</th>
<th>Delete</th>
</tr>
<tr>
<td>coba</td>
<td><input type="checkbox" data-id="1" data-tipe="create"></td>
<td><input type="checkbox" data-id="1" data-tipe="read"></td>
<td><input type="checkbox" data-id="1" data-tipe="update"></td>
<td><input type="checkbox" data-id="1" data-tipe="delete"></td>
</tr>
<tr>
<td>coba 2</td>
<td><input type="checkbox" data-id="2" data-tipe="create"></td>
<td><input type="checkbox" data-id="2" data-tipe="read"></td>
<td><input type="checkbox" data-id="2" data-tipe="update"></td>
<td><input type="checkbox" data-id="2" data-tipe="delete"></td>
</tr>
<tr>
<td><input type="button" id="btnUpdate" value="Update"/>
</tr>
jQuery
$(function(){
$('#btnUpdate').click(function(){
var cb = [];
$.each($('input[type=checkbox]:checked'), function(){
cb.push($(this).data('id') + ' -> ' +$(this).data('tipe'));
});
$('#status').val(cb.join("\n"));
})
});