Reputation: 1040
In the above fiddle I have got 2 text fields, a checkbox and a text. What I require is I need to get the checkbox value and 2 text field values into an array of this structure.
array= array(
[0]=>array(
[0]=>checkbox1,
[1]=>field1,
[2]=>input1),
[1]=>array(
[0]=>checkbox2,
[1]=>field2,
[2]=>input2)
)
Im building this application in codeigniter. I need to post this array using ajax and process it in php. So I want the values in either array format or json as shown above.
Upvotes: 1
Views: 801
Reputation: 388316
Try
$('#add').click(function() {
var result = $('#mytable tr:has(input:checkbox:checked)').map(function() {
var $this=$(this), row =[];
row.push($this.find('input[name="checker1"]').is(':checked'));
row.push($this.find('input[name="field1"]').val());
row.push($this.find('input[name="input1"]').val());
return [row]
}).get();
console.log(result);
});
Demo: Fiddle
Upvotes: 5