divstar
asked on
Javascript: How to create a form with repeatable input fields?
I have a html form with a drop down menu with a list of names. The user can select one of the names from this list, but I would like a button next to it that says "add another person" which will use javascript to add another identical drop down menu below it so they can choose as many people as they like.
Below I have put some example html. When the user clicks "Add Another" I want a new row to be inserted into the table with an identical dropdown menu.
Does anyone know how to do this?
Below I have put some example html. When the user clicks "Add Another" I want a new row to be inserted into the table with an identical dropdown menu.
Does anyone know how to do this?
<form id="form1" name="form1" method="post" action="">
<table width="569" border="0">
<tr>
<td>Your Name </td>
<td><label>
<input type="text" name="textfield" />
</label></td>
</tr>
<tr>
<td>Your Friend/s Name s </td>
<td><label>
<select name="select">
<option value="jim">Jim</option>
<option value="bob">Bob</option>
<option value="joe">Joe</option>
</select>
<input type="button" name="add" value="Add Another Person" onclick="addAnother();" />
</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
ASKER
This works great - if i wanted to later refer to each field say in a php script, what name/s would each succesive child be given? Im guessing $_POST['select'] would give me the value of the first row, what about the others?
Thanks
Thanks
Well.... couple things:
1) I dont do PHP, sorry.
2) Right now they dont have names. If you would like them to have names then we can do that.
3) I screwed it up a bit. It wasnt working right in FF (wrote too fast for my own good).
This code corrects the FF problem, and gives each subsequent row a new name. In this case the names are sequential "row1, row2, etc".
And finally...I'm goin home. Wont be back till tommorrow afternoon. Hopefully this gets you on your way.
dday
1) I dont do PHP, sorry.
2) Right now they dont have names. If you would like them to have names then we can do that.
3) I screwed it up a bit. It wasnt working right in FF (wrote too fast for my own good).
This code corrects the FF problem, and gives each subsequent row a new name. In this case the names are sequential "row1, row2, etc".
And finally...I'm goin home. Wont be back till tommorrow afternoon. Hopefully this gets you on your way.
dday
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is perfect, thankyou
Your welcome.
dday
Open in new window