Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Forms on a Single Page - JQuery

Tags:

jquery

I have multiple forms on a single page with the same named variables within each form.

I need to be able to changed the specific values for one form but not the others.

Ie.

I want to be able to set the value of Var2 for form2, but not the values of Var2 for form1.

Any ideas?

Thanks

like image 297
Oliver Avatar asked Sep 14 '26 12:09

Oliver


1 Answers

Ideally, give the forms their own IDs and use the Descendant Selector:

$("#form1 input[name=foo]").val("something");

or select it by the order in which it appears in the DOM using eq (as Alxandr points out):

$("form:eq(0) input[name=foo]").val("something"); // select the first form
like image 140
karim79 Avatar answered Sep 16 '26 06:09

karim79



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!