I am struggling with a javascript/jquery issue. I have multiple forms that are created within a foreach loop and multiple javascript functions that are created in a foreach loop.
Essentially, the first form looks like this:
<form role="form" action="/save/parishioner" id="1" name="1" method="post">
<input type="text" class="form-control" name="acct_number" id="acct_number" value="test" onchange="save1()" />
<input type="text" class="form-control" name="first_name" id="first_name" value="name" onchange="save1()"/>
</form>
The second form looks like this:
<form role="form" action="/save/parishioner" id="2" name="2" method="post">
<input type="text" class="form-control" name="acct_number" id="acct_number" value="test" onchange="save2()" />
<input type="text" class="form-control" name="first_name" id="first_name" value="name" onchange="save2()"/>
</form>
And the functions looks like this:
alert($('form[name="2"]').serialize());
alert($('form[name="3"]').serialize());
When I try to serialize the data and alert it, the first alert returns blank and the second alert shows the second form serialized.
Why is it not finding the first form?
I would greatly appreciate any help!