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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:01:51+00:00 2026-05-14T18:01:51+00:00

I have a table that looks like this: <table name=exercises id=workout-table> <tr> <th>Name</th> <th>Reps/Intervals</th>

  • 0

I have a table that looks like this:

<table name="exercises" id="workout-table">
<tr>
<th>Name</th>
<th>Reps/Intervals</th>
<th>Sets</th>
<th>Weight/Distance/Time</th>
</tr>


[%- i=0 %]
[% WHILE i<=10 %]
<tr class="workout-rows">
<td><input type="text" name="workout[exercise][[% i %]][name]" /></td>
<td><input type="text" name="workout[exercise][[% i %]][repetitions]" size="3"/></td>
<td><input type="text" name="workout[exercise][[% i %]][sets]" size="3"/></td>
<td><input type="text" name="workout[exercise][[% i %]][weight]" size="4"/></td>
</tr>
[% i = i + 1 %]
[% END %]

</table>

That template code is Template::Toolkit code that basically just generates an index so I can keep track of elements in what will become an HoAoH from Catalyst::Plugin::Params::Nested. This is the javascript that actually adds the row to the table on button click:

$("#add-row").click(function(){
       var size = $(".workout-rows").length;
       //size += 1;
       var row ='<tr class="workout-rows">' +
        '<td><input type="text" name="workout[exercise][' + size + '][name]" /></td>' +
        '<td><input type="text" name="workout[exercise][' + size + '][repetitions]" size="3"/></td>' +
        '<td><input type="text" name="workout[exercise][' + size + '][sets]" size="3"/></td>' +
        '<td><input type="text" name="workout[exercise][' + size + '][weight]" size="4"/></td>' +
        '</tr>';

       $("#workout-table >tbody tr:last").after(row)
    });

I really really don’t like the idea of copy-pasting the table row markup into the script itself, as it’s repetitive and non-intuitive. I’ve tried .clone stuff, which works great for copying the row verbatim, but it doesn’t keep track of the number of rows dynamically like I need it to.

So basically I’ve pared it down to needing to find out how to mess with the name of each input so that it can reflect the loop index appropriately, so Catalyst::Plugin::Params::Nested will build the correct structure.

Thoughts?

  • 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-14T18:01:52+00:00Added an answer on May 14, 2026 at 6:01 pm

    You should make a function that returns a table clone. I use this for templating all the time:

    <div id="tableTemplate" style="display: none;">
        <table>
          <tr class="workout-rows">
            <td> <input type="text" name="" /> </td>
            <td> <input type="text" name="" size="3" /> </td>
            <td> <input type="text" name="" size="3" /> </td>
            <td> <input type="text" name="" size="4" /> </td>
          </tr>
        </table>
    </div>
    

    Then, you clone that template.

    function createTableRow(size)
    {
        var template = $('#tableTemplate').clone(true);
        template = template.find('tr'); // Dont need to clone the table tag
        template.find('td:nth-child(1)').find('input').attr('name', 'workout[exercise][' + size + '][name]');
    
        // Similar logic for the other names
    
        return template;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that looks something like this: CREATE TABLE student_results(id integer, name
I have a table that looks like this: id datatype name value 0 nvarchar(255)
I have a table that looks like this user_id | name | created_on |
I have a MySQL table that looks like this: id (int primary) name (text)
Suppose I have a table, Foo, that looks like this: ID | Name |
I have a categories table that looks like this: id | name | parent
I have a table that looks like this: category category_id name category_seo_friendly_url left_id right_id
I have an in-memory table that might looks something like this: Favorite# Name Profession
I have a table in oracle that looks like this: name | type |
I have a table that looks like this: Id | Name | Parent ---+-------------------------+-------

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.