1

Js Fiddle

jsfiddle

What I Require

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)

              )

Edit

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.

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah thats what I wass looking for.
can you edit the code such that only row with checked checkbox of a class are obtained.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.