I have multiple rows with input fields, and a seperate button for each row.
Since the form is dynamic, e.g some rows might appear from database, more rows can be added by a button, assigning each form/input an ID is difficult.
What is the easiest way for me to get the values from the input fields that are in the same row as the submit button?
(I can use Jquery)
What I have tried:
In the code below, my thought was to wrap each row in a form tag, and have the button submit the current form (e.g the one the button is within) in the onclick function.
But it seems to instead just submit the first form element on the page (which is a completely different form).
(wrapping each row in a form might be unnecessary?)
<form>
<input name="name">
<input name="phone">
<button onclick"save(this.form)">Save</button>
</form>
<form>
<input name="name">
<input name="phone">
<button onclick"save(this.form)">Save</button>
</form>
<form>
<input name="name">
<input name="phone">
<button onclick"save(this.form)">Save</button>
</form>
Pseudocode for function:
function save(inputElements)
{
var phone = ???
var name = ???
}