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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:53:57+00:00 2026-06-12T11:53:57+00:00

Wasn’t too sure exactly how to title this question, but here’s the issue that

  • 0

Wasn’t too sure exactly how to title this question, but here’s the issue that I’m having:

I need to be able to submit an array or a linked list of data via an HTML form. Since this array could be of variable length I have two options:

  1. Use some form of delimiter (for instance, comma-delimited items in a list)
  2. Have multiple inputs (per array item) dynamically generated as new items need to be added

I would like to pursue the second option, although I felt that since this particular project will have many such “array inputs”, I should create a jQuery plugin so that I can more easily implement this feature into future forms.

As I work on this I’ve also been adding functionality for multiple input types, selects, select multiples (via a delimiter), and linked inputs (for instance – having two text inputs for “first name” and “last name” which must be submitted as a pair)

I’ve got a basic layout for how I think it should work:

(function($) { // Self-calling anonymous function to avoid namespace collisions or compatibility issues

    $.fn.dynamicList = function( options ) { // jQuery plugin definition

        /* Set up default options here */
        defaults = {
            option1: "value1",
            option2: "value2"
        };
        var options = $.extend( defaults, options );

        /* Step 1. Add a jQuery-UI plus icon to the DOM */
        /* Note: I have an option to specify where this icon should go in the DOM. It defaults right after the last input */
        plus = $("<span>").addClass( 'jquery-ui-classes' );
        this.last().after( plus );

        /* Step 2. Add a table to the DOM for displaying added values */
        /* Note: I have an option to specify where this table should go in the DOM. It defaults right after the plus icon */
        plus.after( table );

        /* Step 3. Add a handler for our plus button */
        this.delegate( plus, 'click', function() {
            /* Read the inputs, add their values to the table, empty the inputs */
            /* Also, the last column of the table contains a minus button */
            /* This is where I THOUGHT my first issue was.... */
            minus = $("<span>").addClass( 'jquery-ui-classes' );
            table.append( row ).append( minus );
        });

        /* Step 4. Add a handler for our minus button */
        /* Since the minus is created within the plus handler we can't use "minus" here */
        /* Instead I use a class name to locate it */
        this.delegate( '.jquery-ui-minus-class', 'click', function() {
            /* Remove the relevant row from the table */
            $(this).parents('tr').remove();
        });

        /* Step 5. Add our submit handler */
        this.parents('form').first().submit(function() {
            /* We want all of the data in the table to be submitted with the form */
            /* Therefore we create an input per cell and name it accordingly */
            /* The name is just the name of the original input plus "[]" to make it an array */
            /* This is where I thought my second problem was */
        });

        return this; // Maintain chain-ability

    };

)(jQuery);

This code is called on the inputs that you wish to replace with the dynamic list. If you have multiple inputs selected then they will become a list of linked data (such as the first and last name example). An example of how to call this would be the following:

<html>
    <head>
        <!-- Include jQuery and my dynamic list library here -->
        <script>
            $('#fn,#ln').dynamicList();
        </script>
    </head>
    <body>
        <form>
            <input id="fn" name="first_name" />
            <input id="ln" name="last_name" />
        </form>
    </body>
</html>

This will create a dynamic list in which you can type in a first and last name then click the plus button (now to the right of or under the last name input based on your CSS rules) and it will add a row to a table containing the first name in one column, last name in another, and a minus button in the last. You can continue to type names and hit this plus button and the table is extended downward infinitely. Upon submitting the form (via a submit button or any other method) the table cells should become inputs.

I thought that the first problem I would encounter was within the plus handler. Since I am inside a function called by clicking on the plus button, the “this” keyword now refers to the plus icon’s DOM element. I can’t grab the value of the inputs to add them to the table. One proposed solution I had was to create a global variable which is a copy of the object on which the dynamic list function was called like so:

    .
    .
    .
        /* Step 2. Add a table to the DOM for displaying added values */
        /* Note: I have an option to specify where this table should go in the DOM. It defaults right after the plus icon */
        plus.after( table );

        var dynamicList = this;

        /* Step 3. Add a handler for our plus button */
        this.delegate( plus, 'click', function() {
            /* Read the inputs, add their values to the table, empty the inputs */
            /* Also, the last column of the table contains a minus button */
            /* This is where I THOUGHT my first issue was.... */

            for( i = 0; i < dynamicList.length; i++ ) {
                // dynamicList.get(i) will give us each input in order
            }

            minus = $("<span>").addClass( 'jquery-ui-classes' );
            table.append( row ).append( minus );
        });
    .
    .
    .

My concern with this is that if I instantiate multiple dynamic lists they will override one another. Is this true? If so, how do I overcome this?

My second issue that I thought I’d run into was similar. Upon submitting the form I need to find the table to get the values to submit AND find the inputs in order to get the names under which they should be submitted.

However upon playing around with the code to try and fix it myself, I ran into an issue much sooner than expected.

Uncaught TypeError: Object [object Object] has no method 'replace'
jquery-1.6.2.min.js:16
f.each.f.fn.(anonymous function)     jquery-1.6.2.min.js:17
f.fn.extend.delegate     jquery-1.6.2.min.js:17
$.fn.dynamicList     jquery.dynamicList.js:76
(anonymous function)      test.php:16
f.extend._Deferred.e.resolveWith     jquery-1.6.2.min.js:16
e.extend.ready     jquery-1.6.2.min.js:16
c.addEventListener.B     jquery-1.6.2.min.js:16

Lookin at line 76 of my dynamic list code, it’s the following line:

this.delegate( plus, 'click', function() {

Can I not call .delegate() since “this” refers to more than one jQuery object? Or can I not call .delegate() because “this” isn’t a parent element of the plus icon? And once this issue is resolved, how do I solve my other two issues?

EDIT –

I modified the title and I found a solution to my problem on line 76. I’m not sure exactly how .delegate() works, because at first I tried:

this.first().parent().delegate( plus, 'click', function() {

and it was still upset at me. Then I realized that I could just use the .click() function instead (I kinda goofed)

plus.click( function() {

I used similar logic when creating the minus button per row. I added minus.click() after creating the minus button and before inserting it into the DOM, saving me the trouble of using .delegate() anywhere in the code.

Still not sure how to get the values from the input fields within the plus handler since the “this” keyword has been overwritten at this point to refer to the plus button, not my input fields.

  • 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-12T11:53:58+00:00Added an answer on June 12, 2026 at 11:53 am

    I modified the title and I found a solution to my problem on line 76. I’m not sure exactly how .delegate() works, because at first I tried:

    this.first().parent().delegate( plus, 'click', function() {
    

    and it was still upset at me. Then I realized that I could just use the .click() function instead (I kinda goofed)

    plus.click( function() {
    

    I used similar logic when creating the minus button per row. I added minus.click() after creating the minus button and before inserting it into the DOM, saving me the trouble of using .delegate() anywhere in the code.

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

Sidebar

Related Questions

I wasn't sure what to title this question. Here's my goal: On page one,
I wasn't sure how to word this exactly. But I have a model that
I wasn't really sure how to title this, but basically I am having an
I wasn't sure exactly how to phrase the question Title. I have this block
Okay I wasn't really sure how to word this question, but basically what I
Wasn't sure how to write a good title for this question... :) I'm new
I wasn't even sure how to title this right. I have a page that
I wasn't sure what the best way to word this question is but basically
I wasn't sure how to title this question. I create a UDP connection using
I wasn't sure how to word this in the title but lets say you

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.