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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:15:24+00:00 2026-06-15T21:15:24+00:00

I have this form where you can click a link to clone the form

  • 0

I have this form where you can click a link to clone the form fields. I also have a selction if radio button at the top of each clone that hides and shows the checkbox with it. I am unable to figure out why I can do it on first iteration and how to make it work for each clone.

my html looks like this

              <tr> // if the first radio button is selected, the checkbox appears and disappears on selecting 2nd
              <td width="250px"><span style="color: #cc0000;">*</span> Please check the costs that apply:</td>
              <td><input id="Cost_1" type="radio" value="15" name="Costs"/> First Cost: $15 <br/>
              <input id="Cost_2" type="radio" value="10" name="Costs"/> Second cost: $10 <br/>
              <tr id="special_offers">
                  <td>
              <input  type="checkbox" value="5" name="special_offers"/> <span id="optional_span">Special Offers: $5

          <tr>
            <td> First name:</td>
            <td><input name="first_name_id_1" type="text" id="first_name_id_1" size="15" class="required"></td>
              </tr>
          <tr>
            <td> Last name:</td>
            <td><input name="last_name_id_1" type="text" id="last_name_id_1" size="15" ></td>
          </tr>
          <tr>

    </tbody>
    <tr>
        <td><a href="#" onClick="addFormField(); return false;">Register additional attendee</a></td>    
      </tr>
      <tr>  

And my functions:

 function addFormField() {

            var currentCount =  $('.multiplerows').length;
              var newCount = currentCount+1;
            var lastRepeatingGroup = $('.multiplerows:last')
            var newSection = lastRepeatingGroup.clone();
            newSection.find('input').val(''); //clears the text fields//
            $('input[type=radio]',newSection).removeAttr('checked');

            $('input[type=checkbox]',newSection).removeAttr('checked');
            newSection.insertAfter(lastRepeatingGroup);
            newSection.find("input").each(function (index, input) {
                input.id = input.id.replace("_" + currentCount, "_" + newCount);
                input.name = input.name.replace("_" + currentCount, "_" + newCount);
            });
            newSection.find("label").each(function (index, label) {
                var l = $(label);
                l.attr('for', l.attr('for').replace("_" + currentCount, "_" + newCount));
            });
            return false;



        };

        $("input[name='Costs']").click(function() {
          if(document.getElementById('Cost_1').checked) {

            $("#special_offers").show();

          } else {

            $("#special_offers").hide();

           ;
          }
        });

For some reason the fiddle ain’t working, but I don’t have problem cloning the elements on this form, my problem is to grey out the check box if user clicks second radio button on top and to have that option available, each time user clicks to register a new attendee.
Hopefully, the fiddle might give you some idea.
http://jsfiddle.net/qnAHq/7/

  • 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-15T21:15:25+00:00Added an answer on June 15, 2026 at 9:15 pm

    OK, I’ve patch it up a little bit. There were a few misconceptions that were never make it to work, not in the logic format it was so I had to modify it a little bit.
    It’s not pretty but it works and I hope it doesn’t mess your concept.
    The onClick attr trigger was not working so I’ve changed the design a little bit. I guess you’ll be able to modify if it has to be the other way, I could help you if any issues.

    However If you invest time in event driven designs you’ll be much more error prone. In this manner of js coding you’ll always have problems and it’s not maintainable. Lets say you want to change your logic you’ll have to modify a lot. This time spent for debugging you can put it in improvement of coding.

    Here’s the fiddle http://jsfiddle.net/qnAHq/40/ , BR

    <table>
        <tbody class="multiplerows">
            <tr>
                <td width="250px"><span style="color: #cc0000;">*</span> Please check the costs that apply:</td>
                <td>
                    <input id="Cost_1" type="radio" value="45" name="Costs1" class="costs"
                    />Cost 1: $45
                    <br/>
                    <input id="Cost_2" type="radio" value="15" name="Costs1" class="costs"
                    />Cost 2: $15
                    <br/>
                    <tr id="speial_offers">
                        <td>
                            <input type="checkbox" value="15" name="special_offers" /> <span id="optional_span"> Special Offers</span>
    
                        </td>
                </td>
                </tr>
                <tr>
                    <td>First name:</td>
                    <td>
                        <input name="Billing_first_name_id_1" type="text" id="Billing_first_name_id_1"
                        size="15">
                    </td>
                </tr>
                <tr>
                    <td>Last name:</td>
                    <td>
                        <input name="Billing_last_name_id_1" type="text" id="Billing_last_name_id_1"
                        size="15">
                    </td>
                </tr>
                <tr>
                    <td class="hr" colspan="2">
                        <hr />
                    </td>
                </tr>
        </tbody>
        <tr>
            <td><a href="#" id="regCtrl">Register additional attendee</a>
    
            </td>
        </tr>
    </table>
    

    ​

    js:

    (function(window,undefined){
    
            $(function(){
                $('#regCtrl').click(addFormField);
                $("input.costs").click(costsInpHandler);
            });
    
            var formcount = 1;
    
            function addFormField() {
                var lastRepeatingGroup = $('.multiplerows:last');
                var newSection = cloneSection(lastRepeatingGroup);        
                cloneSectionSettings(newSection,lastRepeatingGroup);
    
                return false;
            };
    
    
            function cloneSection(lastRepeatingGroup) {
                var newSection = lastRepeatingGroup.clone();
                var costsInp = $("input.costs", newSection);
                $("input.costs", lastRepeatingGroup).each(function(i){
                    var originInpVal = $(this).val();
                    $(costsInp[i]).attr("value",originInpVal);
                });
                formcount++;
                costsInp.click(costsInpHandler);
    
                return newSection;
            }
    
    
            function cloneSectionSettings(newSection,lastRepeatingGroup){
                var currentCount = $('.multiplerows').length;
                var newCount = currentCount + 1;
                //newSection.find('input').val(''); This one was clearing your input price values so == '15' never occurs 
                $('input[type=radio]', newSection).removeAttr('checked');
                $('input[type=checkbox]', newSection).removeAttr('checked');
                newSection.insertAfter(lastRepeatingGroup);
                newSection.find("input").each(function (index, input) {
                    input.id = input.id.replace("_" + currentCount, "_" + newCount);
                    var n = input;
                    input.name = input.name.replace("Costs" + currentCount, "Costs" + newCount);
                });
                newSection.find("label").each(function (index, label) {
                    var l = $(label);
                    l.attr('for', l.attr('for').replace("_" + currentCount, "_" + newCount));
                });
    
            }
    
    
            function costsInpHandler() {
                var parent = $(this).parents('tbody.multiplerows');
                var certCost1 = $(this);
                var inital = certCost1.is(":checked");
    
                var optionalSpan = $("#optional_span", parent)[inital ? "removeClass" : "addClass"]("gray");
                var optionalCost = $("input[name='special_offers']", parent).attr("disabled", !inital);
                if ($("input.costs:checked", parent).val() == '15') {
                    optionalSpan["addClass"]("gray");
                    optionalCost.attr("checked", false);
                    optionalCost.attr("disabled", true);
                } else {
                    optionalSpan["removeClass"]("gray");
                    optionalCost.removeAttr("disabled");
                }
            }
    
        })(window);
    
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this form to serialize once i click the submit button, <form class=cashier_forms
I have this website (C#/ASP.NET) with a form where the user can register for
I have a form with a secondary address section. In this section you can
I have this web app at the http://autozeep.com/cars each car have it's link to
I have a jQuery dialog that posts a form when the Please Confirm button
I have a javascript link that I'm using as a button on a popup:
I have this form, in which i need to populate a combo box with
I have this form: <%= form_tag posts_path, :method => :get, :class => search_nav do
I have this form: <tbody> <tr> <th>ID</th> <th>Name</th> <th>Birthdate</th> <th><input type=text autofocus=autofocus name=textinput1/></th> <th><input
I have this Form I am trying to upload my image but every time

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.