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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:33:11+00:00 2026-06-11T02:33:11+00:00

I have a page that needs to create dynamic form fields as often as

  • 0

I have a page that needs to create dynamic form fields as often as the user needs, and I am trying to use Ajax to tie it in to my database for faster form entry and to prevent user typos.

So, I have put my Ajax returned data into popup div, the user selects, then the form field is filled in. The problem comes on the cloned fields. They don’t seem to want to bring up the popup div when focused. I am thinking it is something to do with when they get created/added to the DOM.

Here is my JS that creates the clones:

$(document).ready(function() {
    var regex = /^(.*)(\d)+$/i;
    var cloneIndex = $(".clonedInput").length;

    $("button.clone").live("click", function(){
        $(this).parents(".clonedInput").clone()
            .appendTo("#course_container")
            .attr("id", "clonedInput" +  cloneIndex)
            .find("*").each(function() {
                var id = this.id || "";
                var match = id.match(regex) || [];
                if (match.length == 3) {
                    this.id = match[1] + (cloneIndex);
                }
        });
        cloneIndex++;
        numClones=cloneIndex-1;
        //alert("numClones "+numClones);
    });

Here is where I expect to be able to get focus on the correct cloned field and call the popup. The baker_equiv0 id is original code, whereas baker_equiv1 is the first clone.

$('#baker_equiv0').focus(function() { \\ THIS CODE WORKS
$('.popup').fadeIn(500);
$('#results').empty();
// document.enter_data.baker_equiv1.value="test"; THIS LINE WORKS
//alert("numClones "+numClones);
                }); 

$('#baker_equiv1').focus(function() { // THIS DOESN'T EVER FIRE
alert("numClones "+numClones);
$('.popup').fadeIn(500);
$('#results').empty();
}); 

Here is the HTML with the form:

<label for="baker_equiv" class="">Baker Equivalent: <span class="requiredField">*</span></label>
<input type="text" class="cinputsa" name="baker_equiv[]" id="baker_equiv0" size="8" ONKEYUP="get_equiv(this.value);">

If I put this in the HTML code above, it works fine: onfocus="alert(this.id)"

I’d also be interested in how to adjust the JS code to work based on the id array created rather than having to copy code for each potential set of fields clones, i.e., baker_equiv[] rather than baker_equiv0, baker_equiv1, etc.

Thanks all!

  • 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-11T02:33:13+00:00Added an answer on June 11, 2026 at 2:33 am

    After making some assumptions about the HTML, I came up with this :

    HTML :

    <div id="course_container">
        <div class="cloneMe"><!-- wrapper could be any block or inline element eg. <span> or <form> -->
            <label for="input0">Baker Equivalent: <span class="requiredField">*</span></label>
            <input id="input0" type="text" class="cinputsa needsPopup" name="baker_equiv[]" size="8" />
            <button class="clone">Clone</button>
        </div>
    </div>
    

    Javascript :

    $(function() {
        //*** fixed data ***
        var $$ = { //cache of jQuery objects
                course_container: $("#course_container"),
                popup : $("#popup"), //presumably only one popup, so it gets an id
                results: $("#results")
            },
            cloneIndex = 0, // adjust as required to reflect highest index used in the initial HTML
            input_id_prefix = 'input';
    
        //*** event handlers ***
        $$.course_container.on('click', 'button.clone', function() {
            var $clone = $(this).closest('.cloneMe').clone(true, true),
                id = input_id_prefix + ++cloneIndex;
            $clone.find('input').attr('id', id).end().find('label').attr('for', id).end().appendTo($$.course_container);
        });
        $$.course_container.on('focus', 'input.needsPopup', function() {
            $$.popup.fadeIn(500);
            $$.results.empty();
        }).on('keyup', get_equiv);
    });
    

    DEMO

    NOTES

    • clone(true,true) clones deep with data and events.
    • id generation is simplified.
    • The input fields need an id for <label for="..."> to bite on. If you can do without the labels’ for functionality then you should avoid the need for ids completely.
    • clone-button click and input-field keyup and input-field focus handing is delegated to #course_container.
    • get_equiv() is attached by name and in the demo has a simple dummy statement to deomonstrate that it is called.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with a form on it that needs to post to
I have a timed page that I need to use to submit a form
I have a dynamic page that pulls the categories from the database. this page
I have a page that needs to combine data from four different webrequests into
I have a aspx page (details page) that needs to be loaded in a
I have a web page that always needs to stay current. I do not
I have a Web page within my application that needs to call a web
i have been trying to create a rule for dynamic sub-domains and tried many
I'm trying to load a page that is basically an edit form inside a
I have created a dynamic form using jQuery that has two sections, once the

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.