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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:15:48+00:00 2026-05-27T23:15:48+00:00

I am creating a form and I have a field set for client information

  • 0

I am creating a form and I have a field set for client information and the ability to add another field set for another client if needed.

As of now the additional field sets’ field id adds by 1 which is good, but I would like for each of the fields in the field set to add by 1 as well.

var _counter = 0;
function Add() {
_counter++;
var oClone = document.getElementById("client1").cloneNode(true);
oClone.id += (_counter + "");
document.getElementById("placehere").appendChild(oClone);
  • 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-27T23:15:48+00:00Added an answer on May 27, 2026 at 11:15 pm

    Here’s a page that clones and increments the fieldset as well as any children elements within the set. It’s assuming that both fieldset and children inputs have a numeric suffix. i.e. fieldset1 and textfield2, etc.

    Cheers.

    <!DOCTYPE html>
    <html>
    <head>
    
    
      <script type='text/javascript'>
        // store a reference to the last clone so I can increment off that.
        window.lastClone = null;
    
        function incrementId(id) {
          // regexp is looking for text with a number suffix.  adjust accordingly.
          var numberSuffixRegExp = /(.*?)(\d*)$/;
          var regExpMatch = numberSuffixRegExp.exec(id);
          // assuming a match will be made here, and position 1 and 2 are populated.
          var prefix = regExpMatch[1];
          var counter = parseInt(regExpMatch[2]);
          counter++;
          return prefix + counter;
        }
    
        function cloneFieldSet() {
    
          if (!window.lastClone) {
            window.lastClone = 'fieldset1';
          }
    
          var newFieldSet = document.getElementById(lastClone).cloneNode(true);
    
          newFieldSet.id = incrementId(newFieldSet.id);
    
          var tagNames = ['input', 'select', 'textarea'];  // insert other tag names here
          var elements = [];
    
          for (var i in tagNames) {
            // find all fields for each tag name.
            var fields = newFieldSet.getElementsByTagName(tagNames[i]);
            for(var k = 0; k < fields.length; k++){
              elements.push(fields[k]);
            }
          }
    
          for (var j in elements) {
            // increment the id for each child element
            elements[j].id = incrementId(elements[j].id);
          }
    
          document.getElementById("placehere").appendChild(newFieldSet);
          window.lastClone = newFieldSet.id;
        }
    
      </script>
    
    
    </head>
    <body>
    <input type='button' value='Clone' onclick='cloneFieldSet()'/><br/>
    <fieldset id='fieldset1'>
      <table>
    
        <tr>
          <td>Label One:</td>
          <td><input type='text' id='fieldOne1'/></td>
        </tr>
        <tr>
          <td>Label Two:</td>
          <td><input type='text' id='fieldTwo1'/></td>
        </tr>
        <tr>
          <td>Label Three:</td>
          <td><select id='selectOne1'>
            <option>Some Value</option>
          </select></td>
        </tr>
      </table>
    </fieldset>
    <div id='placehere' style='margin:10px 0; border:1px solid black'>
    </div>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have astring directly coming form the database and I am creating object of
I have a jQuery Model windows which contains a form. On creating of the
I have an InfoPath form set as the primary content type on a Form
I am now maintaining a legacy VBA/Access 2000 application for a client. They have
I am creating a portfolio page for m personal site. I have a slider
I am creating a portfolio page for m personal site. I have a slider
Eariler I happily used the following code for creating form elements (inside Zend_Form descendant):
I'm creating a form using the Content Construction Kit (CCK) in Drupal5. I've added
I am creating a form in HTML that will be printed, with fields that
I am creating a form where a user will register with a struts2 application.

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.