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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:35:39+00:00 2026-06-15T19:35:39+00:00

I’m busy with a form that needs to have an option to duplicate certain

  • 0

I’m busy with a form that needs to have an option to duplicate certain fields as many times as the user click, then also it needs to be E-Mailed off, therefore I’m currently on the passport field.

The only problem is, the way i set it up is that for each div element with the class off “passport” it creates an input field. So now where the fields ids are:

1 2 3 4 5 6 7 8 9 10 11 12 13

and when i use jQuery clone:

1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13

and what i need it to be:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

but then how do i assign only the first set of ids to be associated with that one input, for it evaluates the value of the fields.

Anyways, Any help/advice greatly Appreciated.

Heres the jsfiddle: http://jsfiddle.net/dawidvdh/A5naZ/

Heres the code:

jQuery:

    $(document).ready(function() {
    var pass = 1;
    val = 0;
jQuery('div.passport').each(function() {
    var index = "pass"+pass++;
    var passer = "<input class='pass' id="+'"'+index+'"'+" "+" maxlength='1' />";
    var passvalue = $(this).attr('value');
    jQuery(passer).appendTo('#pass');
});

$("#clone").click(function () {
    $('#pass').clone().insertAfter("#pass");
});

function Validatepass() {
    var passValue = '';
    $('.pass').each(function(){ passValue+=($(this).val());});    
    jQuery('#error p').remove();
    var error = jQuery('#error');
    var passNumber = passValue;
    var correct = true;
    if (passNumber.length != 13) {
        correct = false;
    }
    // if no error found, hide the error message
    if (correct) {
        jQuery('.pass').css("border","1px solid #9A8B7D");
    }
    // otherwise, show the error
    else {
        jQuery('.pass').css("border","1px solid #FF0000");
    }
    return false;
}

$('input.pass').keydown(function(e){
    if(e.keyCode == 8){
        $(this).val('');
        $(this).prev().val('');
        $(this).prev().focus();
         Validatepass();
    }
});  

$('input.pass').on('keyup', function(){
    if (this.value.match(/\d+/)) {
        var $this = $(this);
        if ($this.next('input').length) {
          $this.next().focus();
        } else {
          Validatepass();
        }  
    }
});
});

and the HTML:

<div id="pass"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<div class="passport"></div>
<button id="clone">duplicate</button>
  • 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-15T19:35:40+00:00Added an answer on June 15, 2026 at 7:35 pm

    change the click function to this

    $("#clone").click(function () {
        var clonedObj=$('#pass').clone().insertAfter("#pass");
        clonedObj.find('.pass').each(function(){
           this.id='pass' + pass++;
        });
        clonedObj[0].id="WatEverUWant";
    });
    

    EDIT: check this jsfiddle

    EDIT 2: As per your second comment, if u mean changing the id of the cloned div, Added in the code.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.