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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:43:26+00:00 2026-06-12T06:43:26+00:00

I just started from: http://jsfiddle.net/FJFFJ/1/ (by Chain dynamically created dropdowns with JQuery ) It’s

  • 0

I just started from: http://jsfiddle.net/FJFFJ/1/ (by Chain dynamically created dropdowns with JQuery)

It’s really good but now I need to change a bit: clone the last group of selects.

ie.:

+-
Argentina | San Juan | Rawson
Chile     | Santiago | Chiñihue

Then, if I click at “+”, it will clone

Chile | Santiago | Chiñihue

instead of the first one.

  • 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-12T06:43:27+00:00Added an answer on June 12, 2026 at 6:43 am

    This is actually a harder question than I thought it would be. Apparently when you clone the set of SELECT elements it can’t change to something which isn’t displayed. Took me about an hour or so to figure out exactly what was going on, good challenge, thanks!

    What I wound up doing is cloning your template and changing the values manually AND calling the “change” event manually, so that the correct options would be available in the secondary and ternary SELECT elements.

    Version 1: http://jsfiddle.net/m4JTQ/2/

    Version 2 (this is a modified version getting rid of the i iterator: http://jsfiddle.net/Zf7xb/1/

    Here’s the code in case the jsfiddle eventually goes away.

    // Version 1
    $(function() {
    
        // Iterator for the dupe ids
        var i = 0;
    
        $('#clone').click(function() {
            // put the clone() into cloned
            var cloned = $('#template').clone();
    
            // Add .dupe class to cloned
            $(cloned).addClass('dupe');
    
            // Set the id of cloned, use i++ instead of incrementing it elsewhere.
            $(cloned).attr('id', 'duplicate'+ i++);
    
            // Append cloned to #filter
            $(cloned).appendTo('#filter');
    
            // Passing selector rather than iteration                   
            chainItWithId($(cloned));
    
            // If this is NOT the first addition, do some kludge
            if ($('#filter div.dupe').length!==1) {
                // Set the previous clone to lastClone
                var lastClone = $(cloned).siblings('div.dupe:last');
    
                // Set the value of .pais to the value of the previous .pais
                $(cloned).find('.pais').val($(lastClone).find('.pais').val());
                // Do the "change" event manually.
                $(cloned).find('.pais').change();
    
                // Set the value of .provincia to the value of the previous .provincia
                $(cloned).find('.provincia').val($(lastClone).find('.provincia').val());
                // Do the "change" event manually
                $(cloned).find('.provincia').change();
    
                // Set the value of .ciudad to the value of the previous .cudad
                $(cloned).find('.ciudad').val($(lastClone).find('.ciudad').val());
    
            }
    
            // Show the hidden div
            $('#filter div:hidden').show();
    
        });
        $('#remove').click(function() {
            // Remove all but the very last set of options
            if ($('#filter > div').length > 1) {
                $('#filter > div').last().remove();
            }
        });
    
        // Manually do the "click" event
        $('#clone').click();
    });
    
    // Here I'm getting the cloned full selector
    function chainItWithId(cloned) {
        // Chain .provincia to .pais in the current clone
        $(cloned).find('.provincia').chained($(cloned).find('.pais'));
        // Chain .ciudad to .provincia in the current clone
        $(cloned).find('.ciudad').chained($(cloned).find('.provincia'));
    }
    

    No i iterator in this version, it is a bit cleaner.

    // Version 2
    $(function() {
    
        $('#clone').click(function() {
            // put the clone() into cloned
            var cloned = $('#template').clone();
    
            // Add .dupe class to cloned
            $(cloned).addClass('dupe');
    
            // Set the id to the count of div.dupe elements in #filter
            // This will increment 0,1,2,3 as you add elements.
            $(cloned).attr('id', 'duplicate'+ $('#filter div.dupe').length);
    
            // Append cloned to #filter
            $(cloned).appendTo('#filter');
    
            // Passing selector rather than iteration                    
            chainItWithId($(cloned));
    
            // If this is NOT the first addition, do some kludge
            if ($('#filter div.dupe').length!==1) {
                // Set the previous clone to lastClone
                var lastClone = $(cloned).siblings('div.dupe:last');
    
                // Set the value of .pais to the value of the previous .pais
                $(cloned).find('.pais').val($(lastClone).find('.pais').val());
                // Do the "change" event manually.
                $(cloned).find('.pais').change();
    
                // Set the value of .provincia to the value of the previous .provincia
                $(cloned).find('.provincia').val($(lastClone).find('.provincia').val());
                // Do the "change" event manually
                $(cloned).find('.provincia').change();
    
                // Set the value of .ciudad to the value of the previous .cudad
                $(cloned).find('.ciudad').val($(lastClone).find('.ciudad').val());
    
            }
    
            // Show the hidden div
            $('#filter div:hidden').show();
    
        });
        $('#remove').click(function() {
            // Remove all but the very last set of options
            if ($('#filter > div').length > 1) {
                $('#filter > div').last().remove();
            }
        });
    
        // Manually do the "click" event
        $('#clone').click();
    });
    
    // Here I'm getting the cloned full selector
    function chainItWithId(cloned) {
        // Chain .provincia to .pais in the current clone
        $(cloned).find('.provincia').chained($(cloned).find('.pais'));
        // Chain .ciudad to .provincia in the current clone
        $(cloned).find('.ciudad').chained($(cloned).find('.provincia'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started using pygame. I've created my game but it's really unstable and
im just getting started on maven, and im currently following the article from http://www.sonatype.com/books/mvnex-book/reference/simple-project-sect-create-simple.html
I just started taking a class on C# .NET and have found it really
I just started using JSON and found this example from http://imdbapi.com/ : <script type=text/javascript>
I just recently started looking into WatiN and was following the example from http://www.codeproject.com/KB/aspnet/WatiN.aspx
Just started coding in AS3 with FlashDevelop and coming from a C# background, I
I just started learning C++ (coming from Java ) and am having some serious
I just started to learn Rails from railstutorial.org. After installing Rails I cerated an
I just started with WPF. Moved from Window Form. Where do those openDialog, saveDialog
I just started using rapidxml. I 1st create an xml file to read from.

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.