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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:01:54+00:00 2026-05-27T21:01:54+00:00

Here in the below fiddle, i am trying to add and remove table rows

  • 0

Here in the below fiddle, i am trying to add and remove table rows using DOM. As per the script the last field of every row will have a delete button. But i want the delete button in the first field to be the add button which is outside the table.

Only the button in the first row should be add row button. rest of the row should have delete button as it is. How can i do this ?

jsfiddle – http://jsfiddle.net/7AeDQ/33/

Javascript

function deleteRow(row)
{
    var i=row.parentNode.parentNode.rowIndex;
    document.getElementById('POITable').deleteRow(i);
}


function insRow()
{
    console.log( 'hi');
    var x=document.getElementById('POITable');
    var new_row = x.rows[1].cloneNode(true);
    var len = x.rows.length;
    new_row.cells[0].innerHTML = len;

    var inp1 = new_row.cells[1].getElementsByTagName('input')[0];
    inp1.id += len;
    inp1.value = '';
    var inp2 = new_row.cells[2].getElementsByTagName('input')[0];
    inp2.id += len;
    inp2.value = '';
    x.appendChild( new_row );
} 

HTML

<div id="POItablediv">
            <input type="button" id="addmorePOIbutton" value="Add More POIs" onclick="insRow()"/>
    <table id="POITable" border="1">
        <tr>
            <td>POI</td>
            <td>Latitude</td>
            <td>Longitude</td>
            <td>Delete?</td>

        </tr>
        <tr>
            <td>1</td>
            <td><input size=25 type="text" id="latbox"/></td>
            <td><input size=25 type="text" id="lngbox" readonly=true/></td>
            <td><input type="button" id="delPOIbutton" value="Delete" onclick="deleteRow(this)"/></td>

        </tr>
    </table>
  • 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-27T21:01:55+00:00Added an answer on May 27, 2026 at 9:01 pm

    You create new rows by cloning an existing row (and existing button). If you want the behaviour of the button in the first row to be different from other rows, you need to override that changed behaviour in your insRow function (as you do for input ids currently).

    Try changing your code to:

    HTML:

    ...
    <tr>
        <td>1</td>
        <td><input size=25 type="text" id="latbox"/></td>
        <td><input size=25 type="text" id="lngbox" readonly=true/></td>
        <td><input type="button" id="delPOIbutton" value="Add More POIs" onclick="insRow()"/></td>
    </tr>
    ...
    

    JS:

    function deleteRow(evt) {
        var i = evt.target.parentNode.parentNode.rowIndex;
        document.getElementById('POITable').deleteRow(i);
    }
    
    
    function insRow() {
        var x = document.getElementById('POITable');
        var new_row = x.rows[1].cloneNode(true);
        var len = x.rows.length;
    
        new_row.cells[0].innerHTML = len;
    
        var inp1 = new_row.cells[1].getElementsByTagName('input')[0];
        inp1.id += len;
        inp1.value = '';
    
        var inp2 = new_row.cells[2].getElementsByTagName('input')[0];
        inp2.id += len;
        inp2.value = '';
    
        var button = new_row.cells[3].getElementsByTagName('input')[0];
        button.value = "Delete row";
        button.onclick = function(it) {deleteRow(it)};
    
        x.appendChild( new_row );    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here am trying to add a html rows by clicking on the add button
I'm trying to update an element in the XML document below: Here's the code:
Trying not to lose it here. As you can see below I have assigned
I'm a JSON noob and trying to fiddle around with the open table of
here is my fiddle . It shows two headlines and two tables with table-cells.
Here is a js fiddle of my example output: http://jsfiddle.net/Hdzv8/ and below is the
Here is my current question: I'm guessing that my problem (described below) is being
I commented my code below to reflect what I am attempting to do here.
How to find below comment block(s) with javascript/jquery regex: /* some description here */
I know I'm missing something here. In the XSLT transformation below, the actual result

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.