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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:53:26+00:00 2026-05-21T17:53:26+00:00

I have a form that needs to be dynamic, allowing the user to add

  • 0

I have a form that needs to be dynamic, allowing the user to add extra outcomes, w/ however many measures they need associated with it, as depicted here: https://i.stack.imgur.com/EMcoa.png

Here is a sketch of the naming scheme: http://i55.tinypic.com/2s6rh4y.png
enter image description here

Below is the code in some form of working order:
http://jsfiddle.net/bkmorse/yNZcD/2/

What I am having a problem with is making the name of the outcome and measure fields correct.

I need the first outcome textarea to be named: outcome[1]. amd every extra outcome textarea should be outcome[2], outcome[3] and so on.

As for the measure textareas, I need them be named like this: measure[1][0], measure[1][1], measure[1][2] and so on.

The measure textarea’s are named like that, because they will be ran thru a loop when inserted into the database, and the first index number will relate to the outcome.

So when the user adds more measure textareas, the index should increase, for example…

outcome[2], has measure textarea: measure[2][0], measure[2][1], then when they click the plug sign, it will create a new measure textarea, named measure[2][2].

Same thing goes for when clicking the plus sign next to outcome, so the next outcome textarea name would be outcome[2], click for another outcome it would be outcome[3] and so on.

The code works, but I just need to have someone look at it and revise it so it has the name scheme I want.

  • 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-21T17:53:27+00:00Added an answer on May 21, 2026 at 5:53 pm

    ok so I revised allot of code here is the WORKING DEMO by making the measures children of the outcome it will save you parsing in the php side of things.

    I took out the names in the template portion to prevent them from posting.

    I copy the measure form one that’s already close by and clear the value since there is no need to renumber everything since it will already be named correctly.

    I would also strongly suggest you take out the br span and strong tags those things should be handled with css or label would be a good idea

    here is the html

    <form action="#" method="post">
        <div class="outcomegroup" id="template">
            <div class="col">
                <strong>Outcome #<span class="onum">1</span></strong>
                <img class="plus addoutcome" src="http://i54.tinypic.com/2zqzzo7.jpg" />
                <img class="minus removeoutcome" src="http://i53.tinypic.com/29apc8i.jpg" />
                <br />
                <textarea class="outcome"></textarea>
            </div>
    
            <div class="col">
    
                <div class="measure1">
                    <textarea></textarea>
                </div>
    
                <div class="measure">
                    <textarea></textarea>
                    <img class="plus addmeasure" src="http://i54.tinypic.com/2zqzzo7.jpg"/>
                    <img class="minus removemeasure" src="http://i53.tinypic.com/29apc8i.jpg"/>
                </div>
    
            </div>
    
        </div>
    
        <div id="outcome-measure-fields"></div>
        <input type="submit" value="submit" />
    </form>
    

    and the jquery here:

    function renumber() {
        $('#outcome-measure-fields .outcomegroup').each(function(index, value) {
            $(this).find('.outcome').attr('name', 'outcomes[' + index + '][outcome]');
            $(this).find('.measure textarea').attr('name', 'outcomes[' + index + '][measure][]');
            $(this).find('.measure1 textarea').attr('name', 'outcomes[' + index + '][measure][]');
            $(this).find('.onum').text(index + 1);
        });
    
    }
    
    $('.addmeasure').live('click', function() {
        $(this).closest('.measure').clone().insertAfter($(this).closest('.measure')).val('').find('.minus').show();
    });
    
    $('.addoutcome').live('click', function() {
        $('#template').clone().removeAttr('id').insertAfter($(this).closest('.outcomegroup')).find('.minus').show();
        renumber();
    });
    
    $('.removeoutcome').live('click', function() {
        $(this).closest('.outcomegroup').remove();
        renumber()
    });
    
    $('.removemeasure').live('click', function() {
        $(this).closest('.measure').remove();
    });
    
    $('#template').clone().appendTo($('#outcome-measure-fields')).removeAttr('id');
    renumber()
    

    and of course your css

    .outcomegroup {
        overflow: auto;  
    }
    
    #template {
        display: none;
    }
    
    .col {
        float: left;
        margin: 5px;  
        font-size: 20px;
        font-weight: bold;
    }
    
    .plus, .minus {
        width: 20px;
        margin: 2px;
        vertical-align: middle;
        position: relative;
        top: -3px;
    }
    
    .minus {
        display: none;   
    }
    

    let me know how it goes

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

Sidebar

Related Questions

I have a form action that needs to have its value set from a
I have a form that is sending in sizes of things, and I need
I have a form that excepts a file upload in ASP.NET. I need to
We have a form that allows a user to filter a list with by
I have a form with a stage that has a dynamic number of groups
I have form that displays several keywords (standard set of choice lists that changes
I have a form that contains a GridView control which is databound to an
I have a form that I would like to style. specifcally I would like
I have a form that searches all rows in a single table (TServices) that
I have a form that has multiple fields, and for testing purposes is there

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.