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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:08:32+00:00 2026-06-01T09:08:32+00:00

I am trying to dynamically add input fields, which I am able to do.

  • 0

I am trying to dynamically add input fields, which I am able to do. But I am not sure how to go about adding a new name to the input fields. I want it to be an incrementing number. So the first group of input fields would be input1 and each clone that is created increments the number: input1, input2, input3 etc. Does anyone have any idea how I could go about doing this? Here is the jsfiddle: http://jsfiddle.net/liveandream/Xs7m8/

And here is my code:

HTML:

<form action="#" method="post">
<div class="avail">
        <div class="roomType">
          <p>Tipo de Habitación:<br />
        <input type="text" name="roomType" /></p></div>
        <div class="roomType">
          <p><span class="small">Fecha de inicio:</span><br />
        <input type="text" name="Date1" /></p></div>
        <div class="roomType"><p><span class="small">Fecha de Termino:</span><br />
        <input type="text" name="Date2" /></p></div>
        <div class="roomType">
          <p>Tarifa:<br />
        <input type="text" name="roomRate" /></p></div><br clear="all" />
</div>
<input type="submit" value="+" id="copy" />
<input type="submit" value="Add to Database" name="add" />

And my Jquery:

$("#copy").click(function(e) {
       $(".avail").clone().removeAttr('id').insertBefore(this);
       e.preventDefault();
    }); 

Thank you in advance for anyone willing to help!!

  • 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-01T09:08:33+00:00Added an answer on June 1, 2026 at 9:08 am

    (removed my initial answer – overlooked the existing ids in your HTML)

    You could group the post results by room.

    results = {};
    $('form').submit(function(e) {
        e.preventDefault(); // prevent automatic submitting
    
        $('.avail').each(function(index) {
            // Here your have the gather the fields and values in result array;
    
            results['room'+index] = result; // add array with results of one room to result
        });
    
        // Post the result
        $.post($(this).attr('action'), results, function(result) {
             // callback
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a html snippet dynamically which contains named anchors and
I am trying to get a new dynamically created row to add to a
Hello I'm trying to dynamically generate some inputs for my form, but it's not
I am trying to write a jQuery snippet, in which I can add input
I add input text box dynamically and trying to pass values using POST method
I'm trying to dynamically add Images to a ScrollView. Before adding I check if
I am trying and failing to add datepicker to inputs that are created dynamically.
Trying to make a make generic select control that I can dynamically add elements
I am trying to add views to LinearLayout dynamically as much as it possible
we are trying to add ColumnDefinition to a Grid in WPF dynamically from code

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.