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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:22:53+00:00 2026-06-06T17:22:53+00:00

So I got this: HTML <table id=mytable> <tr> <td> </td> <td> </td> </tr> <tr>

  • 0

So I got this:

HTML

<table id="mytable">
<tr>
   <td>

   </td>
   <td>

   </td>
</tr>
<tr>
   <td>
      3. Choose elements:
   </td>
   <td>
      <select name="antal_tidspunkter" id="antal_tidspunkter">
         <option value="1" SELECTED>1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>
      </select>
   </td>
</tr>
    <tr class="highlightedRowStart">
   <td class="borderLeft">
      Time
   </td>
   <td class="borderRight">
      <select name="seats_timeclock[29]">
         <option value="08:00">08:00</option>
         <option value="08:30">08:30</option>
         <option value="09:00">09:00</option>
         <option value="09:30">09:30</option>
         <option value="10:00">10:00</option>
         <option value="10:30">10:30</option>
         <option value="11:00">11:00</option>
         <option value="11:30">11:30</option>
         <option value="12:00">12:00</option>
         <option value="12:30">12:30</option>
         <option value="13:00">13:00</option>
         <option value="13:30">13:30</option>
         <option value="14:00">14:00</option>
         <option value="14:30">14:30</option>
         <option value="15:00">15:00</option>
         <option value="15:30">15:30</option>
         <option value="16:00">16:00</option>
         <option value="16:30">16:30</option>
         <option value="17:00">17:00</option>
         <option value="17:30">17:30</option>
         <option value="18:00" SELECTED>18:00</option>
         <option value="18:30">18:30</option>
         <option value="19:00">19:00</option>
         <option value="19:30">19:30</option>
         <option value="20:00">20:00</option>
         <option value="20:30">20:30</option>
         <option value="21:00">21:00</option>
         <option value="21:30">21:30</option>
         <option value="22:00">22:00</option>
         <option value="22:30">22:30</option>
      </select>
   </td>
</tr>
<tr class="highlightedRowMiddle">
   <td class="borderLeft">
      2:
   </td>
   <td class="borderRight">
      <select name="seats_free_2tables[29]">
         <option value="0">0</option>
         <option value="1">1</option>
         <option value="2" SELECTED>2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>
         <option value="6">6</option>
         <option value="7">7</option>
         <option value="8">8</option>
         <option value="9">9</option>
         <option value="10">10</option>
         <option value="11">11</option>
         <option value="12">12</option>
         <option value="13">13</option>
         <option value="14">14</option>
         <option value="15">15</option>
         <option value="16">16</option>
         <option value="17">17</option>
         <option value="18">18</option>
         <option value="19">19</option>
         <option value="20">20</option>
      </select>
   </td>
</tr>
<tr class="">
   <td class="borderLeft">
     4:
   </td>
   <td class="borderRight">
      <select name="seats_free_4tables[29]">
         <option value="0">0</option>
         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4" SELECTED>4</option>
         <option value="5">5</option>
         <option value="6">6</option>
         <option value="7">7</option>
         <option value="8">8</option>
         <option value="9">9</option>
         <option value="10">10</option>
         <option value="11">11</option>
         <option value="12">12</option>
         <option value="13">13</option>
         <option value="14">14</option>
         <option value="15">15</option>
         <option value="16">16</option>
         <option value="17">17</option>
         <option value="18">18</option>
         <option value="19">19</option>
         <option value="20">20</option>
      </select>
   </td>
</tr>
<tr class="highlightedRowEnd">
   <td class="borderLeft">
      Converttable
   </td>
   <td class="borderRight">
      <select name="seats_converttables[29]">
         <option value="0">0</option>
         <option value="1">1</option>
         <option value="2" SELECTED>2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>
         <option value="6">6</option>
         <option value="7">7</option>
         <option value="8">8</option>
         <option value="9">9</option>
         <option value="10">10</option>
         <option value="11">11</option>
         <option value="12">12</option>
         <option value="13">13</option>
         <option value="14">14</option>
         <option value="15">15</option>
         <option value="16">16</option>
         <option value="17">17</option>
         <option value="18">18</option>
         <option value="19">19</option>
         <option value="20">20</option>
      </select>
   </td>
</tr>
<tr class="spacer">
   <td></td>
</tr>
</table>

jQuery

$(document).ready(function() {

    $("#antal_tidspunkter").bind("change", function() {
        $("#mytable tr:gt(6)").remove();
        for (var i = 1; i < this.value; i++) {
            $("#mytable tr:gt(1):lt(5)").clone().appendTo("#mytable");
        }
    });
});

DEMO: http://jsfiddle.net/bTWQg/

Works like this, when you change the number of elements in the selector, it adds more elements.

My issue with this is that when it duplicate the element, it keeps the name: seats_timeclock[29] so later when I’m working with the handling of the form (PHP), I only receive one element’s data.

Is there anyway to add a random number inside [] from 11111, 99999 each time the element gets duplicated? Otherwise i can’t grab the data filled on the new elements..

  • 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-06T17:22:54+00:00Added an answer on June 6, 2026 at 5:22 pm
    $(document).ready(function() {
    
        // function to generate random number
        // between 1111 to 9999
    
        function randNum() {
            return Math.floor(Math.random() * (9999 - 1111 + 1)) + 1111;
        }
    
        $("#antal_tidspunkter").bind("change", function() {
            $("#mytable tr:gt(6)").remove();
            for (var i = 1; i < this.value; i++) {
                $("#mytable tr:gt(1):lt(5)")
                    .clone()
                    .find('select[name^=seats_timeclock]')
                    attr('name', function() { // changing the name
                        return 'seats_timeclock_[' + randNum() + ']';
                    })
                    .end() // go back to clone element
                    .appendTo("#mytable");
            }
        });
    });
    

    DEMO

    Above code will work without changing HTML and with a single chain statement.

    According to your demo

    $(document).ready(function() {
        // function to generate random number
        function randNum() {
            return Math.floor(Math.random() * (9999 - 1111 + 1)) + 1111;
        }
        $("#antal_tidspunkter").bind("change", function() {
            $("#mytable tr:gt(6)").remove();
            for (var i = 1; i < this.value; i++) {
                var randnr = randNum();
                
                $("#mytable tr:gt(1):lt(5)")
                    .clone()
                    .find('select[name^=seats_timeclock]')
                    .attr('name', function() { // changing the name
                        return 'seats_timeclock[' + randnr + ']';
                    })
                    .end() // need to put end to jump to clone
                    .find('select[name^=seats_free_2tables]')
                    .attr('name', function() { // changing the name
                        return 'seats_free_2tables[' + randnr + ']';
                    })
                    .end()  // need to put end to jump to clone
                    .find('select[name^=seats_free_4tables]')
                    .attr('name', function() { // changing the name
                        return 'seats_free_4tables[' + randnr + ']';
                    })
                    .end()  // need to put end to jump to clone
                    .find('select[name^=seats_converttables]')
                    .attr('name', function() { // changing the name
                        return 'seats_converttables[' + randnr + ']';
                    })
                    .end() // go back to clone element
                    .appendTo("#mytable");
            }
        });
    });
    

    DEMO

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

Sidebar

Related Questions

This one should be easy I've got this HTML <table class=PageNumbers> <tr> <td colspan=3>text3
I have got this html: <div id=myDiv> <p class=readMore></p> <p class=readMore></p> <p class=readMore></p> </div>
I've got this html: <table> <tr style=display:table-row><td>blah</td></tr> <tr style=display:none><td>blah</td></tr> <tr style=display:none><td>blah</td></tr> <tr style=display:table-row><td>blah</td></tr> <tr
I've got an html table that is being generated with php. This list can
I've got a .php page showing a HTML table similar to this one :-
I got this table with a column name Catégorie which I can't rename (long
I got another problem, this time with tables and their borders in HTML (4.01,
I've got this plain HTML: Many things are in my room: a bed, a
I got this jQuery pre-loading script running on a index.html page loading about 10Mb
I got this issue, In the above html I cannot click on the dropdown

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.