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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:45:10+00:00 2026-05-30T08:45:10+00:00

I have this markup <div class=input text> <label for=Experience0ExperienceContent>Experience Content</label> <input name=data[Experience][0][experience_content] class=span3 id=Experience0ExperienceContent

  • 0

I have this markup

<div class="input text">
   <label for="Experience0ExperienceContent">Experience Content</label>
   <input name="data[Experience][0][experience_content]" class="span3" id="Experience0ExperienceContent" type="text">
</div>

It’s possible to clone or duplicate it incrementing the 0 value every time the user make click on a link? I mean all the 0 when user clicks one time the link need to go to 1 then if click again need to go to 2 and so on and of course maintaining the same markup every time, any advice or help?

Cheers and thanks in advance

  • 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-30T08:45:11+00:00Added an answer on May 30, 2026 at 8:45 am

    You could try a little something like this:​

    $("a").click(function() {        
        $("div.input.text")
            .last()
            .clone()
            .appendTo($("body"))
            .find("input").attr("name",function(i,oldVal) {
                return oldVal.replace(/\[(\d+)\]/,function(_,m){
                    return "[" + (+m + 1) + "]";
                });
            });        
        return false;        
    });
    

    As demonstrated here: http://jsfiddle.net/6Xg4S/

    Essentially on click of your anchor it will clone the last div and append it to the body (at least my example appends to the body – obviously you could append it to something more specific or .insertAfter() the last one), then take the number from the middle of the name and increment it via a regex replace.

    Having done that though I’d like to note that you don’t need to give your inputs unique names: all of the server-side technologies that I’d care to use can deal with multiple request parameters with the same name (e.g., Java has getParameterValues() that returns an array).

    EDIT: Here’s a version that clones only the input element, specifically the last input in the div, updates its id, and appends it to the end of the div. As per your comment this no longer changes the name (though obviously you can just throw in an additional .attr() call as above if you want to change the name too). Oh, and also this sets the value to blank (I forgot to do that above).

    $("#extra a").click(function() {   
        var $div = $(this).next();
        $div.find("input")
            .last()
            .clone()
            .appendTo($div.append("<br/>"))
            .val("")
            .attr("id",function(i,oldVal) {
                return oldVal.replace(/\d+/,function(m){
                    return (+m + 1);
                });
            });
        return false;
    });
    

    Demo: http://jsfiddle.net/6Xg4S/4/

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

Sidebar

Related Questions

I have the following markup for my input fields: <div class=required> <label for=Name>Name <em>*</em></label>
I have a submit button with a markup like this: <li class=button><div class=button> <input
Suppose I have this html markup: <div id=wrapper> <pre class=highlight> $(function(){ // hide all
I have my markup like this (for argument's sake) <div id=content></div> <div id=layout></div> <div
I have this markup x 3: <div class=features> <span class=overlay><img src=img/webdesign.png /></span> <h2>Web Design</h2>
Say i have this markup: <div class='current'> </div> <div class='current'> </div> <div class='current'> </div>
Suppose I have this markup: <div id=#titles> <p>Intro text <span>text text</span> text text</p> <ul>
I have this markup in an MVC app. <div id=ingredientlistdiv> <% Recipe recipe =
I have some markup like this: <p><a id=1 href=#>Link 1</a></p> <p id=1show class=starthidden>Hi! I
i have a markup which look like this: <h3>Paragraf3-dummytext</h3> <p> <a name=paragraf3> Quisque id

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.