As this is a bit of a problem involving both javascript and php I hope this is the forum to go with..
Problem:
I have a form containing a table with several <input> etc per row. The user has to be able to both add and remove rows from the table. I need to be able to reference elements both clientside (javascript) and serverside (php).
Let's just deal with one <input> per row, starting out with:
{code}<input name="name1">
<input name="name2">{/code}
User adds one and removes one giving:
{code}<input name="name1">
<input name="name3">{/code}
So, what I'm looking for is a good (or best) way to handle this.
Possible solution:
on submit, before submitting the form to the server, iterate over all inputs and renaming them to, in this case
{code}<input name="name1">
<input name="name2">{/code}
and then in php, just loop over them
{php}
$i = 0;
while (isset($_POST['name' . ++$i]))
{/php}
However, it seems to me that this is a rather silly approach and would like some input on a good way of dealing with it. Would it for example be possible to use
name="name[]" for non checkbox elements?
Any input would be appreciated