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

  • Home
  • SEARCH
  • 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 7528101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:17:05+00:00 2026-05-30T04:17:05+00:00

I have a tricky situation where I need to duplicate a table row, and

  • 0

I have a tricky situation where I need to duplicate a table row, and then alter the names of the inputs to a very specific format. The inputs are named as follows:

  • data[ProjectRequirement][0][description]
  • data[ProjectRequirement][0][qty]
  • …

Now, when the above row is duplicated, the inputs need to be named as follows:

  • data[ProjectRequirement][1][description]
  • data[ProjectRequirement][1][qty]
  • …

And so the pattern must continue. Duplicating the row is not a problem, and I have used the following method:

$j(\'table.WfTable tr\').live(\'mousedown\', function(e){
   if($j(e.target).hasClass(\'add\')){
      var clone = $j(e.target).parents(\'tr\').clone();
      $j(\'table.WfTable\').find(\'tbody\').append($j(clone));
      // NOW I WANT TO DO THE INPUT NAME CHANGE
   };
});

Ignore the escaped quotes, the JS is output via PHP. So at present, the row is duplicated and the names are the same. Is there a method whereby once duplicated, I can say:

“get the name of each input in the row, look for a field like [0] or [1] etc and change that value to the value of the rows index number in the table DOM element (ie row 1 is index 0, 2 is index 1…)?”

I can only assume that row 1 of table is at index 0 in the DOM tree of that table, and therefore think there must be a way to use that index data to apply to the input names?

Any help is much appreciated.

Simon


EDIT: Here is one table row, created dynamically (cakePHP view)


<tr class="repeat">
<td valign="top" style="width:250px;padding:10px 10px 10px 0;"><input type="hidden" name="data[ProjectRequirement][1][project_id]" value="1" id="ProjectRequirement1ProjectId"><input type="hidden" name="data[ProjectRequirement][1][id]" value="2" id="ProjectRequirement1Id"><div class="input text"><input name="data[ProjectRequirement][1][resource]" style="width:240px;" maxlength="40" type="text" value="Teachers" id="ProjectRequirement1Resource"></div></td>
<td valign="top" style="padding:10px 0;"><div class="input text"><input name="data[ProjectRequirement][1][description]" type="text" value="Any volunteer (part time) teachers" id="ProjectRequirement1Description"></div></td>
<td valign="top" style="width:150px;padding:10px 0;"><input name="data[ProjectRequirement][1][qty]" style="width:70px;float:left;clear:none;" maxlength="10" type="text" value="20+" id="ProjectRequirement1Qty"> <a href="#" class="add"><img src="/trusthau.net/img/buttons/btn_plus.png" style="float:right;clear:none;margin:10px 0 0 0;" class="add" alt=""></a></td>
</tr>
  • 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-30T04:17:07+00:00Added an answer on May 30, 2026 at 4:17 am

    Something like this:

    $().ready(function(){
        $('#table tr.repeat:last').clone().appendTo('#table');
        $('#table tr.repeat:last td input').each(function(){
            var input = $(this),
                name = input.attr('name');
            name = name.replace(/(\d+)/, function(i) {
                return ++i;
            });
            input.attr('name', name);
        })
    });​
    

    http://jsfiddle.net/ZFNDD/4/

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

Sidebar

Related Questions

I have a very tricky situation (for my standards) in hand. I have a
I have a tricky problem. I am in a situation where I need to
I have what seems to be a very tricky situation. I would like to
I have a very tricky problem going on with content inside a textarea on
We've got into a very tricky scenario in a project. We have used lot
I have a situation causing me to have a need to support two different
I have a tricky situation in trying to get information from multiple queries into
I have a tricky situation here. I have a web service written in C#
I have a tricky CSS situation here. Basically I have nested span tags that
I have a tricky rewrite situation where I am needing to rewrite old URL's

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.