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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:16:31+00:00 2026-06-11T21:16:31+00:00

I have a row of text boxes , I have a function to clone

  • 0

I have a row of text boxes , I have a function to clone them based on what number comes into the function. So if there are going to be 4 users then I want the row to clone 4 times to enter the information of the 4 users. But I also want some way to be able to submit this form , I am having trouble figuring out how to give each row a unique class or id for each text box so I can read through them when submitting.

I was thinking adding “1” to each class (or id) to everything in the first row, then “2” to everything in the second. But I am not too sure as to how to do this. I have an example Here In jsFiddle , Since I have tried to add the for loop and clone a certain amount of times , now the clone isn’t even working at all- If anyone has any suggestions , it would really help me out.

<div class="RegisterContainer">
  <div class="RegisterHead"><a>Register Attendees</a></div>
    <div class="placenewrows"></div>
</div>
<br />
<input type="button" onclick="fnCloneTemplate({'number' : '3'});" value="make 3 rows">

<div class="_template">
  <a class="left1">First Name:</a>
  <a class="left2"></a><a class="left2">Last Name:</a>
  <a class="left3">Phone #</a><a class="left4">Email:</a>
  <a class="left5">Optional Comment</a><br />
  <input type="text" class="tFirstName left1"/>
  <input type="text" class="tLastName left2"/>
  <div class="phonenumberbox left3">
    <input type="text" class="first3digits" maxlength="3" />
    <a style="position:relative;top:-1px;">-</a>
    <input type="text" class="next3digits" maxlength="3" />
    <a style="position:relative;top:-1px;">-</a>
    <input type="text" class="last4digits" maxlength="4" />
 </div>                                                                                              <input type="text" class="tEmail left4"/>   

function fnCloneTemplate(x){
    var NumofClones = (x.number * 1);
    for(i=0; i <= NumofClones; i++)
    {
       var newrow = $('._template').clone().removeclass('_template');
        $('.placenewrows').append(newrow);
    }    
}

​

  • 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-11T21:16:32+00:00Added an answer on June 11, 2026 at 9:16 pm

    You can change your function like below, to avoid multiple time cloning.

    function fnCloneTemplate(e){
        var NumofClones = (e.data.number * 1),
            newrow= $('._template').clone().removeClass('_template'); // in your code
                                                                      // removeClass spelling
                                                                      // mistaken
        for (i=0; i<NumofClones; i++)
        {
            $('.placenewrows').append(newrow);
        }    
    }
    

    Using on():

    HTML

    <input type="button"value="make 3 rows" id="make_clone">
    

    jQuery

    function fnCloneTemplate(e){
        var NumofClones = (e.data.number * 1),
            newrow= $('._template').clone().removeClass('_template');
        for (i=0; i<NumofClones; i++)
        {
            $('.placenewrows').append(newrow);
        }    
    }
    
    $('#make_clone').on('click',{'number' : '3'}, fnCloneTemplate);
    

    THE DEMO

    Full Code for clone and unique class

    function fnCloneTemplate(x) {
        var NumofClones = (x.data.number * 1),
            clone = $('._template').clone().removeClass('_template');
        for (i = 0; i <= NumofClones; i++) {
            var newrow =    clone
                            .find('input[type=text]')
                            .attr('class', function(i, oldClass) {                             
                                    return oldClass.replace(/\d/, function(char) {
                                        return +char + i ;
                                    });
                                    return newClass
                                })
                            .end();
            $('.placenewrows').append(newrow);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Access 2003. On a subreport I have arranged a row of text boxes
i have one row of text boxes which is generated with php loop and
Say i have a table row with the two text boxes and i want
I have a data table filled with text in each table row. How do
Currently I have a a text file with data at the first row is
I have a list. Each row includes an Image at left and two text
I have a row full of 1, 2, 3 and null. Why don't there
Overview: I have two text boxes at the top of this form for inputting
I have a html table with a column of text boxes ( mileage ),
I have a gridview having text boxes in template fields and buttons in footer,

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.