I have my markup like this. I want to get the each selected values inside an array. So that I can use them in my php ajax file.
<form id="assign-files">
<table class="send-request">
<tbody>
<tr>
<td>
<input type="checkbox" class="check" name="translation_document_id[]" value="4" >
</td>
<td>File 124</td>
</tr>
<tr>
<td>
<input type="checkbox" class="check" name="translation_document_id[]" value="5" >
</td>
<td>File New</td>
</tr>
<tr>
<td>
<input type="checkbox" class="check" name="translation_document_id[]" value="8" >
</td>
<td>New Docs</td>
</tr>
<tr>
<td>
<input type="checkbox" class="check" name="translation_document_id[]" value="28" >
</td>
<td>New Docs here</td>
</tr>
</tbody>
</table>
<button class="assign btn btn-primary pull-right">Assign Files</button>
</form>
My jquery file is like this
<script>
jQuery(document).ready(function($) {
$('body').on('click', 'button.assign', function() {
var atLeastOneIsChecked = $('input[name="translation_document_id[]"]:checked').length > 0;
if( atLeastOneIsChecked == true ) {
var ids = [];
var Selected = $(this).parents('form').find('input[type=checkbox]');
Selected.find(':checkbox:checked').each(function(i) {
var obj = {};
obj["id"]=$(this).val();
});
console.log(ids);
}
if( atLeastOneIsChecked == false ) {
alert('select at least one checkbox');
}
});
});
</script>
Here I don't get the values for the selected checkbox. How to get the selected values like an array?