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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:55:30+00:00 2026-05-16T04:55:30+00:00

I built a page that automatically generates new divs when you click add product.

  • 0

I built a page that automatically generates new divs when you click “add product.” Each div contains a form with unique names and ids. I used this PHP and AJAX multi-level form tutorial to make my forms – http://www.codingcereal.com/2009/09/autopopulate-select-dropdown-box-using-jquery/

Issue is, I can’t seem to call the values when submitting the form through PHP. Only reason I can think of is something to do with the forms being dynamically generated.

Any ideas? Let me know if you need more info.

        var i = 0;

    $('a#add-product').click(function(event){
        i++;
        $('<div />').addClass('product').attr('id', 'product'+i)
            .append($('<h2><img src="<?php echo base_url();?>img/product.png" alt="" />Product '+i+'</h2>'))
            .append($('<div class="info-line"><label>Division</label><p><select id="selection-'+i+'"><option value="">- Select a Division -</option><option value="abrasives">Abrasives</option><option value="tapes">Bonding, Surface Protection &amp; Tapes</option><option value="packaging">Packaging</option></select></p></div>'))
            .append($('<div class="info-line"><label>Category</label><p><select id="selectionresult-'+i+'"></select><span id="result-'+i+'">&nbsp;</span></p></div>'))
            .append($('<div class="info-line"><label>Product</label><p><select id="selectionresult2-'+i+'"></select><span id="result2-'+i+'">&nbsp;</span></p></div>'))
            .append($('<a class="remove" href="#add-product" id="remove-product'+i+'"><img src="<?php echo base_url();?>img/remove-product.jpg" alt="" />Remove Product</a>'))
            .appendTo("#products");


            // START OF ADDITIONAL PRODUCT DROP DOWNS

                    $("#selectionresult-"+i).hide();
                    $("#selectionresult2-"+i).hide();

                    $("#selection-"+i).change( function() {
                        $("#selectionresult-"+i).hide();
                        $("#selectionresult2-"+i).hide();
                        $("#result-"+i).html('Retrieving ...');
                        $.ajax({
                            type: "POST",
                            data: "data=" + $(this).val(),
                            url: "<?php echo base_url();?>dropdown.php",
                            success: function(msg){
                                if (msg != ''){
                                    $("#selectionresult-"+i).html(msg).show();
                                    $("#result-"+i).html('');
                                }
                                else{
                                    $("#result-"+i).html('<em>No item result</em>');
                                }
                            }
                        });
                    });
                    $("#selectionresult-"+i).change( function() {
                        $("#selectionresult2-"+i).hide();
                        $("#result2-"+i).html('Retrieving ...');
                        $.ajax({
                            type: "POST",
                            data: "data=" + $(this).val(),
                            url: "<?php echo base_url();?>dropdown.php",
                            success: function(msg){
                                if (msg != ''){
                                    $("#selectionresult2-"+i).html(msg).show();
                                    $("#result2-"+i).html('');
                                }
                                else{
                                    $("#result2-"+i).html('<em>No item result</em>');
                                }
                            }
                        });
                    });

            // END OF ADDITIONAL PRODUCT DROP DOWNS 

            //START OF PRODUCT IMAGE PREVIEWS
                var productSelection = document.getElementById("selectionresult2-"+i);
                var productPreview = document.getElementById("product"+i+"image");

                //Accessories
                $('#selectionresult2-'+i).change(function () {
                    if (productSelection.value == "3M Disc Pad Face 1"){
                        productPreview.src = "<?php echo base_url();?>img/3m-disc-pad1.jpg";
                    }
                    else if (productSelection.value == "Belt 1"){
                        productPreview.src = "<?php echo base_url();?>img/belt1.jpg";
                    }
                    else {
                        productPreview.src = "<?php echo base_url();?>img/spacer.gif";
                    }
                });

                //Belts
                $('#selectionresult2-'+i).change(function () {
                    if (productSelection.value == "3M Disc Pad Face 1"){
                        productPreview.src = "<?php echo base_url();?>img/3m-disc-pad1.jpg";
                    }
                    else if (productSelection.value == "Belt 1"){
                        productPreview.src = "<?php echo base_url();?>img/belt1.jpg";
                    }
                    else {
                        productPreview.src = "<?php echo base_url();?>img/spacer.gif";
                    }
                });


    });
  • 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-16T04:55:31+00:00Added an answer on May 16, 2026 at 4:55 am

    If you are generating a new form within each div, then when you submit the page, you won’t be submitting each of the forms you create, but instead just the form the submit button belongs to.

    If you don’t put a new form in each div, then all the new fields will belong to the one you submit and you should be able to get their values.

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

Sidebar

Related Questions

We have a site hosted in IIS6 that we built using the .NET 1.1
in an Iphone app, I am in need of building a page that scroll
I am documenting a library that has a Python component and a JavaScript component.
I am working on implementing a JavaScript web bug that will be inserted into
Im trying to implement a single aspx page with several externals dll's. Following Zimmergren's
I've been considering how you would write a business application in only F# with
I need a method of inserting javascript which is controller/action specific into a layout.
I have a site who's search ranking has plumetted. It should be quite SEO
I am just curious - did anyone got Fiddler to work with Windows Phone
In an ASP.NET MVC application I have a CartController with this AddToCart action: public

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.