How to reference input elements within a specific scope when there are multiple input elements of same kind?
Posted
by
Will Merydith
on Stack Overflow
See other posts from Stack Overflow
or by Will Merydith
Published on 2011-01-07T19:46:30Z
Indexed on
2011/01/07
19:53 UTC
Read the original article
Hit count: 157
How do I select data for input elements within a specific scope? I have the same form multiple times (class "foo-form), and want to ensure I get the values for the hidden inputs within the scope of the form being submitted. Is the scope "this" implied? If not, what is the syntax for selecting input class "foo-text" within the scope of this? Feel free to point me to examples in the jquery docs - I could not find what I was looking for.
$('.foo-form').submit(function() {
// Store a reference to this form
var $thisForm = $(this);
});
<form class="foo-form">
<input type="hidden" class="foo-text"/>
<input type="submit" class="button" />
</form>
<form class="foo-form">
<input type="hidden" class="foo-text"/>
<input type="submit" class="button" />
</form>
<form class="foo-form">
<input type="hidden" class="foo-text"/>
<input type="submit" class="button" /> // user clicks this submit button
</form>
© Stack Overflow or respective owner