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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:47:12+00:00 2026-05-11T03:47:12+00:00

I have two functions to add and remove table rows that contain a form

  • 0

I have two functions to add and remove table rows that contain a form input element. They both work fine, but I have a problem in that I need to show a Remove button input only on subsequently created table rows. My two function are as as follows:

function addRow(table_id){ var clone; var rows=document.getElementById(table_id).getElementsByTagName('tr'); var index=rows.length; var tbo=document.getElementById(table_id).getElementsByTagName('tbody')[0]; clone=rows[index-1].cloneNode(true); tbo.appendChild(clone); }  function delRow(table_id,button){ var row = button.parentNode.parentNode; var tbo = document.getElementById(table_id).getElementsByTagName('tbody')[0];    tbo.removeChild(row); } 

and the html content is:

<form> <table id='mytab'> <tr> <td>Upload File <input type='file' name='uploadfile[]' onchange='addRow('mytab')' /> <input name='del_row' type='button' value='Remove Row' onclick='delRow('mytab',this)'/></td> </tr> </table> </form> 

I am by no means a Javascript expert – more of a newbie – so I’m struggling to come up with a solution.

  • 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. 2026-05-11T03:47:13+00:00Added an answer on May 11, 2026 at 3:47 am

    I’m assuming that you are trying to avoid having the remove button in the first row, but need it there now because you think that to get it in subsequent rows, you need to have it in the row that you are cloning. If, instead, you just insert new HTML for both the upload and delete button inputs in the addRow method you can avoid the clone entirely and it won’t matter what your original row contains.

    function addRow(table_id){    var table = document.getElementById(table_id);    var row = table.insertRow(table.rows.length);    var cell = row.insertCell(0);    var template = table.rows[0].cells[0].innerHTML;    cell.innerHTML = template + '<input type='button' value='Remove Row''                  + ' onclick='delRow(\'' + table_id + '\',this);' />' } 

    This still uses the first row as the template, but you can remove the button from it as it is added by appending to the existing text.

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

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer After re-re-reading your Q, it seams you want to steer… May 11, 2026 at 2:34 pm
  • added an answer One possible solution can be that handle to file are… May 11, 2026 at 2:34 pm
  • added an answer You can capture the MouseEnter and MouseLeave events on both… May 11, 2026 at 2:34 pm

Related Questions

Anyone have any suggestions on how to set up both the php and the
The question, in brief: In MVC, how do you distinguish between a checkbox click
I need to process XML documents of varying formats into records in a MySQL
I have a function that I use to add vectors, like this: public static

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.