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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:29:29+00:00 2026-06-17T16:29:29+00:00

I’m creating a duplicate-able div’s containing check box’s, at the moment on the original

  • 0

I’m creating a duplicate-able div’s containing check box’s, at the moment on the original set of inputs, the check boxes act like radio buttons, but when duplicated it still only works on the first not the second.

Also on submit it only returns one value for the original form in the console, but no value for any duplicates.

Any help greatly appreciated.

JS Fiddle: http://jsfiddle.net/dawidvdh/EEd7c/

jQuery:

//Clone Tracking
var g_counter = 1;
var d_counter = 1;
var dependant = ["dependant"];
var group;
//Clone Tracking
//General Variables
var relation_input_groups = ["relation-group-1"];
//General Variables
//Generate variables
var relation_fields=[0];
var relation_input ="<label>Spouse</label>"+

    "<input type='checkbox' value='spouse' class='relationship' name='relationship' />" +
    "<label>own child</label>"+ 

    "<input type='checkbox' value='ownchild' class='relationship' name='relationship' />" +
    "<label>adopted</label>"+ 

    "<input type='checkbox' value='adopted' class='relationship' name='relationship' />" +
    "<label>stepchild</label>"+ 

    "<input type='checkbox' value='stepchild' class='relationship' name='relationship' />" +
    "<label>parent</label>"+ 

    "<input type='checkbox' value='parent' class='relationship' name='relationship' />" +
    "<label>inlaw</label>"+ 

    "<input type='checkbox' value='inlaw' class='relationship' name='relationship' />" +
    "<label>brother</label>"+ 

    "<input type='checkbox' value='brother' class='relationship' name='relationship' />" +
    "<label>other</label>"+ 

    "<input type='checkbox' value='other' class='relationship' name='relationship' />";
//Generate variables
jQuery(document).ready(function(e) 
{
    //populate jquery generated fields
    jQuery(relation_fields).each(function() 
    {
        jQuery(relation_input).appendTo('#relation-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++;
        currentdep ='dependant-'+g_counter;
        // Clone the Dependant Div and set a new id
        var $clonedDiv = jQuery('#dependant-1').clone(false).attr('id', 'dependant-'+g_counter);
        var relation_newDiv = 'relation-group-'+ g_counter;
        // Find div's inside the cloned object and set a new id's
        $clonedDiv.find('#relation-group-1').attr('id',"relation-group-" + g_counter );
        // You don't need to Loop thru the inputs to set the value
        $clonedDiv.find('input').val('');
        $clonedDiv.find('input:checkbox').removeAttr('checked');
        // Insert the cloned object 
        $clonedDiv.insertAfter("#dependant-" + oldId);

        relation_input_groups.push(relation_newDiv);
    }
    //Cloning Function
    //Validation
    //submit function
    var $unique = $('input[type="checkbox"]');
    $unique.click(function() 
    {
        $unique.removeAttr('checked');
        $(this).attr('checked', true);
    });

    var result = {};
    var dependants;
    var dep_counter = 0;
    jQuery('#submit').click(function()
    {
        jQuery('.dependant').each(function(k, v)
        {
            dep_counter++
            dependants = {};
            result['dependant'+dep_counter] = [dependants];
            dependants['relationship'] = $(v).find('.relationship:checked').val();
        });
        var jsonData = JSON.stringify(result);
        console.log(jsonData);
    });
});

and the HTML:

<div id="dependant-1" class="dependant">
    <div id="label">relationship:</div> <div id="relation-group-1"></div>
</div>

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

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-06-17T16:29:30+00:00Added an answer on June 17, 2026 at 4:29 pm

    The reason why it does not work is you are not attaching the click events to the new cloned elements.

    $(document).on("click", 'input[type="checkbox"]', function() {
        jQuery(this).siblings(":checked").removeAttr('checked');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
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

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.