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

  • Home
  • SEARCH
  • 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 8824323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:35:02+00:00 2026-06-14T06:35:02+00:00

The title isn’t very descriptive but I couldn’t find a better one. Feel free

  • 0

The title isn’t very descriptive but I couldn’t find a better one. Feel free to edit it.

Basically what I’m looking for is the best way to do the following:

add new item

When the user clicks “Add New Item”, a new row is added with an indentical text box and drop down as above. The options I can think of are the following:

  • Hardcode the HTML in the JavaScript code. This is obviously a hideously ugly solution.
  • Assemble the HTML from DOM nodes (or jQuery objects). This is very ugly too.
  • Use a client-side template system. I used one of those once and it was pretty weird (it used <script language="html"> tags to define the templates).
  • Make an ad-hoc client-side “template” and hide it somehow with CSS.
  • Make an AJAX request to fetch the HTML. This is slow and uses server resources unnecessarily.

What do you suggest? I’m not completely satisfied with any of the above solutions.

  • 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-14T06:35:03+00:00Added an answer on June 14, 2026 at 6:35 am

    Assuming the super-simple approach and that your format is in a table:

    <table>
        <tr>
            <td><input type="text" name="item_name" placeholder="item name" /></td>
            <td><select name="item_type"><option value="" selected="selected">Type</option></select></td>
        </tr>
        <tr>
            <td><input type="text" name="item_name" placeholder="item name" /></td>
            <td><select name="item_type"><option value="" selected="selected">Type</option></select></td>
        </tr>
        <tr>
            <td colspan="2" id="add">+ Add new item</td>
        </tr>
    </table>
    

    You can use the following:

    $('#add').on('click',function(e){
        var $this = $(this);
        var $newRow = $this.closest('table').find('tr:first').clone();
        $newRow.find(':input').val('');
        $newRow.insertBefore($this.parent());
    });
    

    Broken down:

    1. We give the last item an ID to make it easier to bind a click event to.
    2. Use jQuery and bind the click event to that ID which:
      • Grabs the current table we’re clicking within ($this.closest('table'))
      • Locates the first row within that table and duplicates it (.clone())
      • Remove any populated values that may be present (.find(':input').val(''))
      • Append this new cloned row to the table just above the “add new item” row ($newRow.insertBefore(...))

    You can also take the template approach, but that’s really up to you and how much control you’d like over the output.

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

Sidebar

Related Questions

Well, i know the title isn't very specific, but i couldn't find a better
Sorry if the title isn't very clear, I couldn't think of anything better... I'm
The title isn't clear as I couldn't think of one but, I have an
The title isn't very clear but I'll try to explain. Having this class: class
Ok, maybe the title isn't the most descriptive thing in the world, but this
If the title isn't accurate enough, please feel free to change it to something
OK, the question title probably isn't the best, but I'm looking for a good
I know the question title isn't amazing, but I can't think of a better
I know the title isn't very elaborate, but I have tried this multiple times
I know the title isn't the most descriptive, but I can't think of a

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.