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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:09:57+00:00 2026-05-17T22:09:57+00:00

Ok lets say I have div with form elements inside of it. I want

  • 0

Ok lets say I have div with form elements inside of it. I want to be able to clone that div with a button click using jQuery and add a version 2 of the form, so ALL of the element IDs will increment by 1 in their name.

<div id="card">
    <!-- PART 1 --> 
    <h1 class="card_build">Build your card options:</h1>

    <select id="country" name="country[]">
        <?php
            include('lib/class_dbcon.php');
            $connect = new doConnect();

            $q = mysql_query("SELECT * FROM country ORDER BY country_id ASC");
            while($row = mysql_fetch_assoc($q))
            {
                echo '<option value="'.$row['country_id'].'">'.$row['country_option'].'</option>';
            }
        ?>
    </select>

    <select id="filter" name="filter[]">
        <option value="">-- Select Filter --</option>
    </select>

    <select id="load_choice" name="load_choice[]">
        <option value="">-- Select Load_choice --</option>
    </select>

    <select id="plastic" name="plastic[]">
        <option value="">-- Select Plastic --</option>
    </select>

    <select id="UG_tipping" name="UG_tipping[]">
        <option value="">-- Select UG/Tipping --</option>
    </select>
    <!-- PART 1 -->
    <!-- PART 2 -->
    <div id="part2" style="margin-top:10px;">
    <h1 class="card_build">Customize the card:</h1>
    <input type="text" name="3rdLine" size="32" class="field" id="3rdLine">
    <input type="text" name="4thLine" size="32" class="field" id="4thLine">
    <input type="text" name="card_value" size="32" class="field" id="card_value">
    <label for="showpoints">Show "Points"?</label>
    <input type="checkbox" value="points" class="checkbox" checked="checked">
    <label for="cobrand">Co-branded?</label>
    <input type="checkbox" value="cobrand" class="checkbox" checked="checked">
    <textarea rows="5" name="message" class="textarea" id="message"></textarea>
    <hr>
    </div>
    <!-- PART 2 -->
</div>
    <a href="#" onCLick="moreFields()">ADD</a>

So if you look at this code and you were to click the ADD link at the end it would duplicate and turn it into and do the same thing to all of the element IDs inside the div as well. One wrench in the works is that I want a MAXIMUM of 5 clones, so the script can only increment 4 times (or 5 it doesn’t really matter, as long as I can see a method to create a maximum).

My only other question is, will the PHP injection remain in tact when a div is cloned? Thanks in advance, I’ve been wracking my brain all night on this 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-05-17T22:09:57+00:00Added an answer on May 17, 2026 at 10:09 pm

    From your code I think your main problem is accessing the group of dropdowns uniquely without conflict. If this is the case, I think that could be achieved without the stress of incrementing the id’s of each element for every group created. If I were to do this, I would approach it as follows.

    First the DOM (an example):

    
    <div id="card">
        <div class="group">
            <select id="country" name="country[]">
                <option>select</option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
            </select>
            <select id="filter" name="filter[]">
                <option>select</option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
            </select>
        </div>
    </div>
    <a id="more" href="">More</a>
    

    Then the jquery:

    
    $(function(){
        var newgroup = $('<div>').addClass('group');
        $('#more').click(function(e){
            e.preventDefault();
            $('.group').first().clone().appendTo(newgroup).appendTo('#card');
        });
    
        $('.group #country').live('change',function(){
            $(this).parent().find('#filter').val(1);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a div #elements with a ul inside.The div has position:
lets say I have a <div id=god> Supertext </div> I want to assign <div
how to have a div that always stay on the screen? Lets say i
Lets say I have a container div, inside of which are div containers of
lets say I have this divs: Js files needed: Jquery & Jquery UI <div
Let's say I have the following scenario: <form action=/something.php method=GET>Click me</div> <script type=text/javascript><!-- $('form').submit(function(e)
Let's say I have two steps of my form that I want my visitors
Lets say I have CSS like this: div.form label input { /* some css
Lets say I have a page on the same domain that I put inside
Lets say I have a div like this: <div id=test class=sourcecode> Some String </div>

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.