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 6469117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:57:15+00:00 2026-05-25T05:57:15+00:00

I am trying to build a system like when any user clicks on an

  • 0

I am trying to build a system like when any user clicks on an “Add” button, it creates two text fields and two drop down selects automatically. I searched on google for the tutorial but all I have managed to find is only how to add text fields, but I need to add Select drop down with remove option.

I have some knowledge in PHP but little in Javascript or Jquery.

Would you please kindly help?

Here is the code that I have found:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<script>
function generateRow() {

var d=document.getElementById("div");
d.innerHTML+="<p><input type='text' name='food'>";

var e=document.getElementById("div");
e.innerHTML+="<input type='text' name='food'>";

}
</script>
</head>

<body>
 <form id="form1" name="form1" method="post" action="">
<label>
 <input name="food" type="text" id="food" />
</label>

  <div id="div"></div>
  <p><input type="button" value="Add" onclick="generateRow()"/></p>
  <p>
  <label>
   <input type="submit" name="Submit" value="Submit" />
  </label>
  </p>
  </form>
  </body>
 </html>
  • 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-05-25T05:57:15+00:00Added an answer on May 25, 2026 at 5:57 am

    In jQuery, to create an element, you can simply do this:

    var newDiv = $("<div>");
    

    Now, that element doesn’t yet exist in the page. You can add it many ways. One common approach is to append it to an existing element. This will append the new div to the body element:

    newDiv.appendTo("body");
    

    This too:

    $("body").append(newDiv);
    

    And this will append it to an element with an id of “foo”:

    newDiv.appendTo("#foo");
    

    So, assuming you want to generate the following HTML each time the button is clicked:

    <div>
        <input name="a" />
        <input name="b" />
        <select name="c">
            <option value="0">Option 1</option>
            <option value="1">Option 2</option>
        </select>
        <select name="d">
            <option value="0">Option 1</option>
            <option value="1">Option 2</option>
        </select>
    </div>
    

    And assuming you want to add that HTML to your div with an id of “div”, your code might look something like this:

    $("input[type=button][value=Add]").click(function (e) {
        e.preventDefault(); // prevent submitting the form.
        var newDiv = $("<div>").appendTo("#div");
        $("<input>").attr("name", "a").appendTo(newDiv);
        $("<input>").attr("name", "b").appendTo(newDiv);
        $("<select>").attr("name", "c").appendTo(newDiv).append(
            $("<option>").val("0").text("Option 1"),
            $("<option>").val("1").text("Option 2"));
        $("<select>").attr("name", "d").appendTo(newDiv).append(
            $("<option>").val("0").text("Option 1"),
            $("<option>").val("1").text("Option 2"));
    });
    

    Here’s a working example: http://jsfiddle.net/v5kvX/

    Edit: Including a remove button. You’ll want to create a <button> the same way we created our other elements, then add a click handler that removes the parent div. Add this line to your function from above:

    $("<button>").text("Remove").appendTo(newDiv).click(function (e) {
        e.preventDefault(); // prevent submitting the form.
        $(this).parent().remove(); // alternatively, you could say: newDiv.remove();
    });
    

    Updated example: http://jsfiddle.net/gilly3/v5kvX/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a user based message system. I'd like messages to show
I'm trying to build a navigation system using categories table with hierarchies. Normally, the
I am trying to build openid login system for my website. To do this
I am trying to set up an automated build system on Windows using Cygwin.
Trying to build sslsniff on a RHEL 5.2 system here. When compiling sslsniff on
We are trying to build a Help Desk ticketing system just for intranet. Deciding
I'm trying to build a Windows installer using Nullsoft Install System that requires installation
We are trying to build a High-Volume Orders Record System. There are three primary
Using PHP and MySQL, I have a forum system I'm trying to build. What
I'm trying to use the System.IO.Log features to build a recoverable transaction system. I

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.