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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:01:54+00:00 2026-06-17T13:01:54+00:00

I try to make some repeatable fields with PHP and Javascript. This works fine,

  • 0

I try to make some repeatable fields with PHP and Javascript. This works fine, but after saving the post (creating an plugin for WordPress) the cloned row will override the latest one. This is because I don’t use unique id’s for each row.

I want to add an ‘id’ attribute with javascript and I want for each row that is created with the id 1 increase. I had already done something similar with PHP, but found out that this is not what I wanted and I am better out with javascript, I think, because when I clone the field with the “add new” button the amount doesn’t increase with +1;

Here is the php code that I had used:

$count = 2;
for ($i = 0; $i < $count; $i++) {

    // Begin a table row
    echo '<tr class="row" id="' . '['.$i.']' . '-repeatable">';
    echo '<td class="order">' . '['.$i.']' . '</td>';

            // Do cool stuff inside the row

    echo '<td class="remove"><a class="repeatable-remove button" href="#">-</a></td>';
    echo '</tr>'; // End .row

} // End for loop

<a href"#" class="button">Add new row</a>

JS code for the repeatable fields:

// Add repeatable row
jQuery('.repeatable-add').click(function() {
    // Clone row
    var row = jQuery(this).closest('.ui-sortable').find('tbody tr.row:last-child');
    var clone = row.clone();

    clone.find('input[type=text], text, textarea, select, input.upload_image').val(''); // Reset the values
    clone.find('.preview_image').attr('src', ''); // Reset the values

    row.after(clone);

    //
    return false;
});

I think I have to do something like this snippet of line:

clone.find('tr.row').attr('id', 'repeatable-' + addInteger);

But how do I increase with +1 inside Jquery/Javascript, like my example in PHP?

  • 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-17T13:01:55+00:00Added an answer on June 17, 2026 at 1:01 pm

    What you want to do is look at the ID of the row you’re cloning and use that ID to give the new row its proper index value. I added two lines of code to your example, one defining a new variable called clonedIdIndex and one using the value in that variable to define a new ID for the cloned row.

    jQuery('.repeatable-add').click(function() {
        // Clone row
        var row = jQuery(this).closest('.ui-sortable').find('tbody tr.row:last-child'),
            clone = row.clone(),
            clonedIdIndex = parseInt( clone.find('tr.row').attr('id').split('-')[1], 10 );
    
        clone.find('input[type=text], text, textarea, select, input.upload_image').val('');    
        clone.find('.preview_image').attr('src', ''); // Reset the values
    
        // Assign new ID
        clone.find('tr.row').attr('id', 'repeatable-' + (++clonedIdIndex));
    
        row.after(clone);
    
        //
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've try to make some code, but I found some problem... This is my
I try to make a displaying list with onmouseover() with some links but they
I try to make a registration form. When user post the fields, i check
I try to make some databinding involving an x:Array defined in the resources, but
I try to make some kind of progress indicator for a simple php loop.
I am creating a website with a friend to try and make some money.
I try to make some connection to an tfs server. I must run this
I wanted to make some simple file recovery software, where I want to try
I try to make an animation with an image in my view but it
i try make some parts of page with fixed style. I have similar HTML:

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.