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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:53:25+00:00 2026-06-11T23:53:25+00:00

I asked another question on this , and got an answer , but still

  • 0

I asked another question on this , and got an answer , but still managed to mess it up. I have a for loop , and I want to make clones of a template in my for loop. I would like each id to be replaced with the id + 0 the first time through the loop. So textbox with id tFirstName would be tFirstName0 and id tLastName would be tLastName0 and so on… Then for the next clone , then next time through the loop it would be tFirstName1 , tLastName1, ect..

The problem with this code is that i is adding one for every text box, so in the first template the id’s are tFirstName0, tLastName1, ect..

I am looking for – if someone has a suggestion to keep i uniform through out the for loop, then increase , then stay uniform through the next loop

 var NumofClones = (4 * 1);
            for (i = 0; i < NumofClones; i++) {
                var newrow = $('._template').clone().removeClass('_template');
                newrow.find('input[type=text]').attr('id', function (i, oldID) {
                    return oldID + i
                });

                $('.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-11T23:53:27+00:00Added an answer on June 11, 2026 at 11:53 pm

    The i in the .attr()‘s callback function refer to the parameter i, not the i in the for loop, change the parameter i of the callback function to some others.

     var NumofClones = (4 * 1);
     for (var i = 0; i < NumofClones; i++) {
         var newrow = $('._template').clone().removeClass('_template');
         newrow.find('input[type=text]').attr('id', function (index, oldID) {
             return oldID + i;
         });
         $('.placenewrows').append(newrow);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question earlier. I am intrigued by std::set but I have another
I asked this question about a year ago on another site but never got
I asked this question yesterday got a pretty good answer but can't figure out
(I asked this question in another way , and got some interesting responses but
I asked another version of this question on the gamedev.SE site earlier today but
This question is related to another question I asked Basically, I have 2 horizontally
I'm sure this was asked somewhere in another question, but the wording used there
I have asked a similar question before and got an convincing answer as well?
Asked the same question here but got no answer, so I'm trying here instead
UPDATE : I asked this question in another form (see below), and it got

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.