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

The Archive Base Latest Questions

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

I’m busy making a clone-able form. I’m currently stuck, I have 13 input fields

  • 0

I’m busy making a clone-able form.

I’m currently stuck, I have 13 input fields for one value being id, and i can clone it and it updates the class of group to “group1”, “group2” etc i need to get the value of the first group of input fields then the second etc.

Here’s the js fiddle: http://jsfiddle.net/dawidvdh/BLdDE/

and here’s the jQuery:

//Clone Tracking
var g_counter = 1;
var d_counter = 1;
var dependants = "dependant"+d_counter++;
var group;
var current_group = jQuery(document.activeElement);
//Clone Tracking
//General Variables

//General Variables
//Generate variables
var id_fields       =   [0,1,2,3,4,5,6,7,8,9,10,12,13];
var passport_fields =   [0,1,2,3,4,5,6,7,8,9,10,12,13];
var cell_fields     =   [0,1,2,3,4,5,6,7,8,9,10];

var id_input = "<input class='id' id="+'"'+"group"+g_counter+++'"'+" "+" maxlength='1' />";
//Generate variables

jQuery(document).ready(function(e) {
//populate jquery generated fields
jQuery(id_fields).each(function() {
    jQuery(id_input).appendTo('#id_field');
});
//populate jquery generated fields
//Cloning Function
jQuery('#clone').click(function(){
    clone_dependant();
});

function clone_dependant(){
    g_counter++;
    var clonedObj=jQuery('#id_field').clone().insertAfter("#id_field");
        clonedObj.find('.id').each(function(){
             $(this).prop('id', 'group'+g_counter).val(''); // chain the commands
    });
};
//Cloning Function
//Validation
function validate_gen(){};
function validate_Id(current_group){
    console.log(current_group);
};
function validate_Pass(){};
function validate_Email(){};
function validate_Cell(){};
//Validation
//Multiple Inputs function
$(document).on('keydown', 'input.id', function(e){
    if(e.keyCode == 8){
        $(this).val('');
        $(this).prev().val('');
        $(this).prev().focus();
         //Validate(current);
    }
});  

$(document).on('keyup', 'input.id', function(){
    var current_group = this.id;
    if (this.value.match(/\d+/)) {
        var $this = $(this);
        if ($this.next('input').length) {
          $this.next().focus();
        } else {
          validate_Id(current_group);
        }  
    }
});
//Multiple Inputs function

});

and the html

<div id="id_field"></div>
<button id="clone">clone</button>

Any Help Greatly Apreciated, Thank you 🙂

  • 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-15T21:31:10+00:00Added an answer on June 15, 2026 at 9:31 pm

    The problem with your code is you are having the same id for all the input's in a group. This will mess it up when extracting then values.

    It will be better if you avoid the id's for the input's completely and give a unique id to the div that encases them as a whole.. (maybe group1 , group2 ....)

    Something of this way should help..

    //Clone Tracking
    var g_counter = 1;
    var d_counter = 1;
    var dependants = "dependant" + d_counter++;
    var group;
    var current_group = jQuery(document.activeElement);
    //Clone Tracking
    //General Variables
    var input_groups = ["group-1"];
    //General Variables
    //Generate variables
    var id_fields = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13];
    var passport_fields = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13];
    var cell_fields = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    
    var id_input = "<input class='id' maxlength='1' />";
    //Generate variables
    jQuery(document).ready(function(e) {
        //populate jquery generated fields
        jQuery(id_fields).each(function() {
            jQuery(id_input).appendTo('#group-1');
        });
        //populate jquery generated fields
        //Cloning Function
        jQuery('#clone').click(function() {
            clone_dependant();
        });
    
        function clone_dependant() {
            var clonedObj = jQuery('#group-1')
                                  .clone().insertAfter("#group-" + g_counter);
            g_counter++;
            var newDivId = 'group-'+ g_counter;
            clonedObj.prop('id' ,newDivId ).find('input').each(function() {
                this.value = ''; // chain the commands
            });
            input_groups.push(newDivId);
        };
        //Cloning Function
        //Validation
    
    
        function validate_gen() {};
    
        function validate_Id(current_group) {
           // console.log(current_group);
        };
    
        function validate_Pass() {};
    
        function validate_Email() {};
    
        function validate_Cell() {};
        //Validation
        //Multiple Inputs function
        $(document).on('keydown', 'input.id', function(e) {
            if (e.keyCode == 8) {
                $(this).val('');
                $(this).prev().val('');
                $(this).prev().focus();
                //Validate(current);
            }
        });
    
        $(document).on('keyup', 'input.id', function() {
            var current_group = this.id;
            if (this.value.match(/\d+/)) {
                var $this = $(this);
                if ($this.next('input').length) {
                    $this.next().focus();
                } else {
                    validate_Id(current_group);
                }
            }
        });
    
        $('#getvalues').on('click', function(){
            $.each(input_groups , function(i){
                var id = input_groups[i];
                var values = $.map($('#'+id + ' input') , function(e,i){
                    return $(e).val();
                }).join(' :: ');
    
                console.log('The values inside ' + id + ' : are ' + values);
            });            
        });
        //Multiple Inputs function
    });​
    

    Check Fiddle

    UPDATE

    If that’s the case I would clone the dependant div itself instead of doing it for all the div’s specifically.

    Secondly you do not need to loop over each group to set the same value..

    Try this

    function clone_dependant() {
            // Store the value of the previous Id to insert the cloned div..
            var oldId = g_counter;
            g_counter++;
    
            // Clone the Dependant Div and set a new id
            var $clonedDiv = jQuery('#dependant-1').clone(false)
                                               .attr('id', 'dependant-'+g_counter);
            var cell_newDiv = 'cell-group-'+ g_counter;
            var age_newDiv = 'age-group-'+ g_counter;
            var pass_newDiv = 'pass-group-'+ g_counter;
            var id_newDiv = 'group-'+ g_counter;
    
            // Find div's inside the cloned object and set a new id's
            $clonedDiv.find('#group-1').attr('id',"#group-" + g_counter );
            $clonedDiv.find('#age-group-1').attr('id',"#age-group-" + g_counter );
            $clonedDiv.find('#cell-group-1').attr('id',"#cell-group-" + g_counter );
            $clonedDiv.find('#pass-group-1').attr('id',"#pass-group-" + g_counter );
    
            // You don't need to Loop thru the inputs to set the value
            $clonedDiv.find('input').val('');
    
            // Insert the cloned object 
            $clonedDiv.insertAfter("#dependant-" + oldId);
    
            cell_input_groups.push(cell_newDiv);
            age_input_groups.push(age_newDiv);
            pass_input_groups.push(pass_newDiv);
            input_groups.push(id_newDiv);
        };
    

    UPDATED FIDDLE

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
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
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.