Brian G
Brian G

Reputation: 54992

JQuery Conditionally submit forms

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.

Upvotes: 0

Views: 1729

Answers (3)

Jeremy B.
Jeremy B.

Reputation: 9216

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.

Upvotes: 1

Nathan Strutz
Nathan Strutz

Reputation: 8123

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.

Upvotes: 2

James Curran
James Curran

Reputation: 103485

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

$("td > input:checked > form").submit();

Upvotes: 0

Related Questions