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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:13:17+00:00 2026-06-17T09:13:17+00:00

I am busy with a form duplication, when submit is pressed, I would like

  • 0

I am busy with a form duplication, when submit is pressed, I would like it to parse to json in the following format:

{ "dependant1": [
  { "name": "daniel"},
  ],"dependant2": [
  { "name": "steve"},
  ]
}

with each added dependant, at the moment, if i add more then one dependant it returns “{} {}” but if theres only one dependant it returns “{“name”:”steve”}.

any help greatly apreciated.
Heres the code:

jQuery:

        //Clone Tracking
var g_counter = 1;
var d_counter = 1;
var dependant = ["dependant"];
var group;
//Clone Tracking
//General Variables
var name_input_groups = ["name-group-1"];
//General Variables
//Generate variables
var name_fields=[0];
var name_input = "<input class='name' />";
//Generate variables
jQuery(document).ready(function(e) {
    jQuery(name_fields).each(function() {
        jQuery(name_input).appendTo('#name-group-1');
    });
    //populate jquery generated fields
    //Cloning Function
    jQuery('#clone').click(function() {
        clone_dependant();
    });

    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 name_newDiv = 'name-group-'+ g_counter;
        // Find div's inside the cloned object and set a new id's
        $clonedDiv.find('#name-group-1').attr('id',"name-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);
        name_input_groups.push(name_newDiv);
    };
    //Cloning Function
    function validate_gen() {};
//submit function
var dep_counter = 0
jQuery('#submit').click(function(){
    $('.dependant').each(function(k, v){
        dep_counter++;
        var dependants = {};
    dependants['name'] = jQuery("#name-group-" + dep_counter).find('input').val();
        var json = JSON.stringify(dependants); 
        console.log(json);
    });
});
});

and heres the HTML:

<div id="dependant-1" class="dependant">
    name<div id="name-group-1"></div>
</div>
<div id="test"></div>

<button id="clone">clone</button>
<button id="submit">submit</button>

and the jsFiddle link – http://jsfiddle.net/dawidvdh/TzRu8/2/

Thanks.

  • 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-17T09:13:18+00:00Added an answer on June 17, 2026 at 9:13 am

    simply used the following code and it worked perefectly:

        var result = {};
    var dependants;
    jQuery('#submit').click(function(){
        $('.dependant').each(function(k, v){
            dependants = {};
            dependants['name'] = $(v).find('.name').val();
            dependants['surname'] = $(v).find('.surname').val();
            dependants['id'] = idNumber;
            dependants['age'] = $(v).find('.age').val();
            dependants['gender'] = $(v).find('.gender').val();
            dependants['cell'] = cell_values;
            dependants['passport'] = pass_values;
            dependants['relationship'] = $(v).find('.relationship:checked').val();
            result['dependant'+g_counter] = [dependants];
        });
    
        var jsonData = JSON.stringify(result);
    
        console.log(jsonData);
    
        $.ajax({
            type: "POST",
            url: "mail.php",
            dataType: "json",
            data: {parameters: jsonData}
        });
    
    });
    

    Thanks everyone 🙂

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

Sidebar

Related Questions

I have a XAML form that I would like two independent features threaded out
How can I show a busy server icon to a user for Django form
I currently have code similar to this for a form: $('#some-form') .submit(function() { //
This is the submit button: <h:commandButton actionListener=#{regBean.findReg} action=#{regBean.navigate} value=Search /> This is the form:
Quick question: I have a very busy form going on that I have developed
Hey guys still busy with the registration form article I found, I followed the
Hi everyone im currently busy trying to convert a duplicatable form to an jsonstring,
I'm busy with a form that needs to have an option to duplicate certain
I'm busy making a clone-able form. I'm currently stuck, I have 13 input fields
I am busy programming a win32 program in assembly with a form and buttons...

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.