I have two forms in a html site and each form has an inputbox and a submit button
<div id="ausgabe">
<form class="forms">
<input type="text" placeholder="bla">
<button type="submit" class="btn btn-primary btn-small">TestA</button>
</form>
<form class="forms">
<input type="text" placeholder="bla">
<button type="submit" class="btn btn-primary btn-small">TestB</button>
</form>
</div>
$(".forms").submit(function(event)
{
event.preventDefault(); // Prevent the form from submitting via the browser
var test = $(this);
var wert = test.parent().find(":input:first").val();
alert("Button pressed"+wert);
});
Then i type "TestA" in the first inputbox and press the submit-button for this form and get an "Button pressed TestA" alert.
Then i type "TestB" in the second inputbox which belongs to the second form and i expect this result "Button pressed TestB" but i get "Button pressed TestA" again
How can i get the value of the inputbox which belongs to the its form? My idea was to get the parent of the button which is pressed and find an inputbox there.
I'am generate this forms dynamicly from a java servlet backend and i not want to create ids for each form.
Best Regards rubiktubik