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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:28:02+00:00 2026-05-11T20:28:02+00:00

<tr> <td><input name=of[1][dsn] type=text size=6 /></td> <td><input name=of[1][gc] type=text size=6 /></td> <td><input name=of[1][ys] type=text

  • 0
<tr>
<td><input name="of[1][dsn]" type="text" size="6" /></td>
<td><input name="of[1][gc]" type="text" size="6" /></td>
<td><input name="of[1][ys]" type="text" size="3" /></td>
<td><input name="of[1][ym]" type="text" size="3" /></td>
<td><input name="of[1][yl]" type="text" size="3" /></td>
<td><input name="of[1][s]" type="text" size="3" /></td>
<td><input name="of[1][m]" type="text" size="3" /></td>
<td><input name="of[1][l]" type="text" size="3" /></td>
<td><input name="of[1][xl]" type="text" size="3" /></td>
<td><input name="of[1][xxl]" type="text" size="3" /></td>
<td><input name="of[1][xxxl]" type="text" size="3" /></td>
<td><input name="of[1][xxxxl]" type="text" size="3" /></td>
<td><input name="of[1][xxxxxl]" type="text" size="3" /></td>
<td><input name="of[1][total]" type="text" size="4" /></td>
</tr>

I currently have this being cloned using jQuery and would like to have it to where the number in the “name” attribute is raised by +1 every time it is duplicated. “of[1][dsn]” to “of[2][dsn]” etc. How can I do this? Below is what I had tried to use, but that was flat out replacing what was already there.

 ("input").each(function(index, element){$(element).attr("name", index);});

This is what I am using to actually clone the table row:

var clonedRow = $("table tr:last").clone();     
$("table tr:last").clone(true).insertAfter("table tr:last").append(clonedrow);
  • 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-11T20:28:02+00:00Added an answer on May 11, 2026 at 8:28 pm

    Okay you need something like this. First we clone, then we increase the number in the name by one, and then we apply that to each of the inputs, and then we insert them into the DOM.

    var $cloned = $('#selector').clone();
    var oldIndex = $cloned.find('input').attr('name').match(/\d+/);
    var newIndex = parseInt(oldIndex,10)+1;
    $cloned.find('input').each(function(){
       var newName = $(this).attr('name').replace(oldIndex, newIndex);
       $(this).attr('name', newName);
    });
    $cloned.appendTo('#something');
    

    This assumes that the number to be increased is always the first number in the name string (it can however be multiple digits).

    Edit In response to you comment: You need to clone the cloned object in the rest of your code. Thus always clone the lastest clone. You should rewrite the code to something like this:

    function clone(){
      var $cloned = $('table tr:last').clone();
      var oldIndex = $cloned.find('input').attr('name').match(/\d+/);
      var newIndex = parseInt(oldIndex,10)+1;
      $cloned.find('input').each(function(){
         var newName = $(this).attr('name').replace(oldIndex, newIndex);
         $(this).attr('name', newName);
      });
      $cloned.insertAfter('table tr:last');
    }
    $('p.add-btn').click(clone);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: <form action= id=credentials method=post> <label for=name id=nameLabel >Name*:</label> <input type=text
I have two text input fields: Name:<input id=name type=text value= name=username> Age:<input id=age type=text
In HTML I have some input tags with labels: <label>Address <input type=text name=address /></label>
I have an input, type text, element which is being validated using MVC3 validation
I have input with either some given or empty data-file: <input type=text value=path/to/file.gif name=some_file
I have the following code structure: <input type=checkbox name=some_name_1 value=some_val /> <input type=text name=input_name_1
I have html code like <ul> <li>Some Name <a class=rud href=#>remove</a><input type=text value=one readonly=readonly
I have string like this : <input name=my_name id=my_id value=my_value class=my_class /> I would
i have currently 5 input name box which i want to insert into mysql
If i have a string like this: $myString = input/name/something; How can i get

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.