Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:29:33+00:00 2026-06-02T07:29:33+00:00

Bit of a badly written question, but basically I have a Form for users

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:29:35+00:00Added an answer on June 2, 2026 at 7:29 am

    Your HTML code has a mistake: there are tr and td tags but there is no table tag. Here is example of how you can get what you want:

    <script type="text/javascript">
    
    function addTextboxes() {
      var cont = document.getElementById("selects_container");
      cont.innerHTML += document.getElementById("first_select").innerHTML;
    }
    </script>
    ...
    <div id="selects_container">
      <div id="first_select">
        <select name="ingredientselect[]"> 
          <option value="" selected="selected">Ingredient</option>
          <option value="" selected="selected">Ingredient</option>
        </select>
      </div>
    </div>
    <input type="button" id="addingred" onclick="addTextboxes();" value="Add Ingredient">
    

    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 input tag and passed to server:

    <script type="text/javascript">
    function addTextboxes() {
      var new_value = document.getElementById("the_select").value;
      document.getElementById("selected_values").value += new_value + ",";
      document.getElementById("selected_text").innerHTML += new_value + "<br>";
    }
    </script>
    ...
    <input id="selected_values" name="selected_values" type="hidden">
    <div id="selected_text"></div>
    <select name="ingredientselect[]" id="the_select"> 
      <option value="" selected="selected">Ingredient</option>
      <option value="" selected="selected">Ingredient</option>
    </select>
    <input type="button" id="addingred" onclick="addTextboxes();" value="Add Ingredient">
    

    On server side:

    $selected_values_array = explode(",", $_POST["selected_values"]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bit of a newbie question here. I have a form and one of it's
Bit of a noob question but: I have a custom class defined as: public
I have asked a similar question to this one already but I think it
Bit of a strange question here i know. but i wanted to know if
Bit support question. Apologies for that. I have an application linked with GNU readline.
Bit of a philosophical question. If you have a public website with a site
Bit of an odd question but is there a way of seeing what objects
Bit of a bizarre question, but does anyone know the actual limit to the
Bit of a beginner question here: Say I have a block of xml: <root>
Bit confused here, I have an on-demand instance but do I get charged even

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.