Multiple forms on one page - jQuery

I have several forms on one page with the same named variables in each form.

I need to be able to change specific values ​​for one form, but not others.

Those.

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

Any ideas?

thank

+3
source share
1 answer

Ideally, give the forms your identifiers and use the Descendant Selector :

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

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

$("form:eq(0) input[name=foo]").val("something"); // select the first form
+3
source

Source: https://habr.com/ru/post/1776071/


All Articles