Bit of a badly written question, but basically I have a Form for users adding their values to the database. One of the fields needs a drop down box that is populated with the values in my database field. However the user may want to have more than one select box (all the drop down selections need to post to the same database field).
<form method="POST" action="addcocktail.php" >
<tr><td>Cocktail Name: </td><td><input type="text" name="cocktailname" /> </td></tr>
<tr><td>Ingredients: </td><td><input type="text" name="ingredients" /> </td></tr>
<select name="ingredientselect">
<option value="" selected="selected">Ingredient</option>
<option value="" selected="selected">Ingredient</option>
</select>
<input type="button" id="addingred" onclick="addTextboxes();" value="Add Ingredient">
<tr><td>How To: </td><td><input type="text" name="howto" /> </td></tr>
<input type="submit" value="add" />
</form>
I need a Javascript function that will basically duplicate one of my select options, so the user can choose how many “ingredients” they want; on button click. (I’ve been playing around with the addElement but to no avail)
And Im also wondering how to pull the database values straight into the select box options.
Any help is apppreciated, thanks -Matt
Your HTML code has a mistake: there are
trandtdtags but there is notabletag. Here is example of how you can get what you want:This way isn’t perfect and have a perfomance problem, but it’s simple.
You should add
[]to name of select, then you can retrieve values of all selects in PHP.Also, I can advise you not to multiply selects or options, but add selected values to page as text. Selected values can be stored in hidden
inputtag and passed to server:On server side: