james james - 7 months ago 6
HTML Question

How to specify which input goes to which form

I have rows of data where each column is a

<td>
that contains an
<input>
. The challenge is when the user pushes the submit button, I want 2 forms to be submitted, with differing inputs. How can I specify in the input which form that input should go to?

The reason this is funky is because normally, you'd have this:

<form>
<table>
<tr>
<td><input /></td>
</tr>
</table>
</form>


So the input goes to whichever form it's nested within. But in my case, since it's impossible to do this kind of teasing out because I need:

<form1>
<form2>
<table>
<tr>
<td><input1 /></td>
<td><input2 /></td>
<td><input2 /></td>
<td><input1 /></td>
<td><input1 /></td>
</tr>
</table>
</form1>
</form2>


If there is no way to make the above work except to do something like the below:

<table>
<tr>
<form1>
<td><input1 /></td>
<td><input1 /></td>
<td><input1 /></td>
</form1>
<form2>
<td><input2 /></td>
<td><input2 /></td>
</form2>
</tr>
</table>


That's also an acceptable answer. I'd just prefer to avoid the above because ironically from a UX perspective, it makes the most intuitive sense to mix up the inputs across the forms.

Answer

You can't achieve this without splitting your inputs in 2 distinct forms as you already mentioned or without using javascript. Well, the third option would be to "separate" forms on the back-end by their names (form[1][name], form[2][name], etc.)