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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:51:50+00:00 2026-05-27T12:51:50+00:00

I have a table and I want from user add rows which who want.

  • 0

I have a table and I want from user add rows which who want. I was looking in google about this way , And I found cods but It dosen’t work.

This is my code

Plz help me where is the problem in It.

    <html>
<head>
<script type="text/JavaScript">
                function addRow(r){
                    var root = r.parentNode;//the root
                    var allRows = root.getElementsByTagName('tr');//the rows' collection
                    var cRow = allRows[0].cloneNode(true)//the clone of the 1st row
                    var cInp = cRow.getElementsByTagName('table');//the inputs' collection of the 1st row
                    for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names)
                cInp[i].setAttribute('name', cInp[1].getAttribute('name') + '_' + (allRows.length + 1));
                }
                var cSel = cRow.getElementsByTagName('select')[0];
                    cSel.setAttribute('name',cSel.getAttribute('name')+'_'+(allRows.length+1));//change the selecet's name
                    root.appendChild(cRow);//appends the cloned row as a new row
                }


                function deleteRow(r){
                var i=r.parentNode.parentNode.rowIndex;

                document.getElementById('table2000').deleteRow(1);
                }
                </script>
                </head>
                <body>
<table style="width:950px">
<tr>
                <th align="center" rowspan="2">Program</th>
                <th align="center" colspan="2">Time</th>
                <th align="center" rowspan="2">Pm/Am</th>
                <th align="center" rowspan="2">Price</th>
                <th align="center" rowspan="2">Note</th>
                <th align="center" rowspan="2">Ration</th>
                <th align="center"rowspan="2" >Action</th>
            </tr>
            <tr>
                <th>From</th>
                <th>to</th>

            </tr>



<tr>
<td>
<select name="program[]" width="200%;">

                               <OPTION >Option 1</OPTION>
                                <OPTION >Option 2</OPTION>
                                <OPTION >Option 3</OPTION>
                                <OPTION >Option 4</OPTION>
                         </select>
</td>
<td>
                    <select name="from[]" width="70"  >
                        <option>1 </option>
                        <option>2 </option>
                        <option>3 </option>
                        <option>4 </option>
                        <option>5 </option>
                        <option>6 </option>
                        <option>7 </option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                    </select>

</td>
<td>
                    <select name="to[]">
                        <option>1 </option>
                        <option>2 </option>
                        <option>3 </option>
                        <option>4 </option>
                        <option>5 </option>
                        <option>6 </option>
                        <option>7 </option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                    </select>

</td>
<td>
    <select name="time[]">
        <option value="ص">am</option>
        <option value="م">pm</option>
    </select>
</td>
<td>
    <input type="text" value="" name="massat[]">
</td>
<td>
    <input type="text" value=""  name="note[]">
</td>
<td>                    
    <input type="text" value="" name="rating[]">
</td>
<td>
 <img class="add" src="http://almedinah.net/wp-content/themes/blogitty/images/add-button.png" style=":hover{background:#000;}"onclick="addRow(this.parentNode.parentNode)">
 <img class="add" src="http://almedinah.net/wp-content/themes/blogitty/images/remove-button.png" style=":hover{background:#000;}"onclick="deleteRow(this)">

 </td>

</tr>
</table>
                </body></html>
  • 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-27T12:51:51+00:00Added an answer on May 27, 2026 at 12:51 pm

    I tried to fix it as below; please note that if you use php, the input name with subscript [] will be automatically assigned an index (hence no need to calculate an index in your javascript and I commented those lines out ).

    <html>
    <head>
    <script type="text/JavaScript">
    
                    function addRow(r){
                        var root = r.parentNode;//the root
                        var allRows = root.getElementsByTagName('tr');//the rows' collection
                        //var cRow = allRows[0].cloneNode(true)//the clone of the 1st row
                        var cRow = allRows[2].cloneNode(true)//the clone of the 1st row
                        //var cInp = cRow.getElementsByTagName('table');//the inputs' collection of the 1st row
                        /*
                        var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row
                        for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names)
                            //cInp[i].setAttribute('name', cInp[1].getAttribute('name') + '_' + (allRows.length + 1));
                            cInp[i].setAttribute('name', cInp[i].getAttribute('name') );
                        }
                    //var cSel = cRow.getElementsByTagName('select')[0];
                    var cSel = cRow.getElementsByTagName('select');
                    for(var i=0;i<cSel.length;i++){
                        //cSel.setAttribute('name',cSel.getAttribute('name')+'_'+(allRows.length+1));//change the selecet's name
                        cSel[i].setAttribute('name',cSel[i].getAttribute('name'));//change the selecet's name
                        }
                        */
                        root.appendChild(cRow);//appends the cloned row as a new row
                    }
    
    
                    function deleteRow(r){
                    var i=r.parentNode.parentNode.rowIndex;
                        if (i != 2)
                        document.getElementById('table2000').deleteRow(i);
                    }
                    </script>
                    </head>
                    <body>
    <table style="width:950px" border="2" id="table2000">
    <tr>
                    <th align="center" rowspan="2">Program</th>
                    <th align="center" colspan="2">Time</th>
                    <th align="center" rowspan="2">Pm/Am</th>
                    <th align="center" rowspan="2">Price</th>
                    <th align="center" rowspan="2">Note</th>
                    <th align="center" rowspan="2">Ration</th>
                    <th align="center"rowspan="2" >Action</th>
                </tr>
                <tr>
                    <th>From</th>
                    <th>to</th>
    
                </tr>
    
    
    
    <tr>
    <td>
    <select name="program[]" width="200%;">
    
                                   <OPTION >Option 1</OPTION>
                                    <OPTION >Option 2</OPTION>
                                    <OPTION >Option 3</OPTION>
                                    <OPTION >Option 4</OPTION>
                             </select>
    </td>
    <td>
                        <select name="from[]" width="70"  >
                            <option>1 </option>
                            <option>2 </option>
                            <option>3 </option>
                            <option>4 </option>
                            <option>5 </option>
                            <option>6 </option>
                            <option>7 </option>
                            <option>8</option>
                            <option>9</option>
                            <option>10</option>
                            <option>11</option>
                            <option>12</option>
                        </select>
    
    </td>
    <td>
                        <select name="to[]">
                            <option>1 </option>
                            <option>2 </option>
                            <option>3 </option>
                            <option>4 </option>
                            <option>5 </option>
                            <option>6 </option>
                            <option>7 </option>
                            <option>8</option>
                            <option>9</option>
                            <option>10</option>
                            <option>11</option>
                            <option>12</option>
                        </select>
    
    </td>
    <td>
        <select name="time[]">
            <option value="?">am</option>
            <option value="?">pm</option>
        </select>
    </td>
    <td>
        <input type="text" value="" name="massat[]">
    </td>
    <td>
        <input type="text" value=""  name="note[]">
    </td>
    <td>                    
        <input type="text" value="" name="rating[]">
    </td>
    <td>
     <img class="add" src="http://almedinah.net/wp-content/themes/blogitty/images/add-button.png" style=":hover{background:#000;}"onclick="addRow(this.parentNode.parentNode)">
     <img class="add" src="http://almedinah.net/wp-content/themes/blogitty/images/remove-button.png" style=":hover{background:#000;}"onclick="deleteRow(this)">
    
     </td>
    
    </tr>
    </table>
    </body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a table from which I allow the user to add and
I have 2 tables which I want to query from. The first table (lets
I have a HTML table as follows. I want retrieve row values from this
I have the typical emp table from which i want to fetch the hierarchical
I want to add rows to a table dynamically inside a for loop. User
--I have some rows from my table which I would like to export in
i have users table and i have posts table i want select from users
I have table a joining table b, I only want the records from table
I have the following table: I want to insert values from the MySQL workbench.
I have a HBase table (from java) and i want to query the table

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.