tags:

views:

880

answers:

3

I have a table with multiple rows. Each row is a form. I want to use JQuery to submit all the forms that have the check box checked. The form is posting to an IFrame so there is not much need for AJAX.

So far I have:

    $("form").submit();

which submits the form. but all forms. There is arbritary number of rows, could be 80-100.

A: 

This is kinda a guess since I'm not sure of your layout, but here goes....

$("td > input:checked > form").submit();
James Curran
If the selector returns null, you'll get an error.
EndangeredMassa
The selector should never return null, only a collection with no items.
James Curran
+2  A: 

Off the top of my head, you probably want something like this

$("input:checked").parent("form").submit();

This will find the checked form fields, traverse up to find the parent form object and submit that.

Nathan Strutz
except if all rows are in the same form, it just submitted the whole form.
Jeremy B.
The poster said "Each row is a form" so my example still works.
Nathan Strutz
+1  A: 

I'm not sure about submit, because I've done this in .post(), but here is what I've used to get what I want to send on the submission:

var formElements = $("form").find("input:checked").parent("td").serialize();

you should be able to send back that variable.

Jeremy B.