The following script will send $_POST['id']=[1,2,3] to the server.
Instead I wish to either send $_POST['id']=[[1,'extra1'],[2,'extra2'],[3,'extra3']] to the server, or send both $_POST['id']=[1,2,3] and $_POST['extra']=['extra1','extra2','extra3'] to the server.
I could do so by iterating over the table, but the HTML is PHP generated, and instead I would like to modify the HTML to make doing so as straightforward as possible.
How is this best accomplished?
https://jsfiddle.net/5a8cLt08/2/
$('#go').click(function() {
var data = $('#mytable tbody input.cb:checked').serializeArray();
console.log('data', data);
$.post('ajax.php', data, function(json) {
console.log('json', json);
}, 'json');
});
<table id='mytable'>
<tbody>
<tr>
<td>
<input class="cb" type="checkbox" value="1" secondValue="extra1" name="id[]">
</td>
<td>bla1</td>
<td>
<input class="cb" type="checkbox" value="2" secondValue="extra2" name="id[]">
</td>
<td>bla2</td>
<td>
<input class="cb" type="checkbox" value="3" secondValue="extra3" name="id[]">
</td>
<td>bla3</td>
</tr>
</tbody>
</table>
<button id="go">Go</button>