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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:43:34+00:00 2026-05-18T08:43:34+00:00

I have a bit of a problem. I’m trying to add,remove and edit items

  • 0

I have a bit of a problem. I’m trying to add,remove and edit items in an array of objects, showing its content in a html table,but without form submission. So far I’ve managed to add items ( thanks to David Calhoun ), but now I facing a new issue, since I don’t know how to get the row index (when I click the delete image) ,so that I can delete that row. Is there any way to achieve this?

here’s my code

<script>

var table = [];
function addDetail()
{
    table.push({            
        price: document.getElementById('price').value,
        description: document.getElementById('descripcion').value
    });

    showRow(table.length-1);
    resetEntries();

}
function resetEntries()
{
    document.getElementById('price').value='';
    document.getElementById('descripcion').value='';
    document.getElementById('price').focus();

}

function showRow(i)
{
    if (table.length>0){
        var tbl = document.getElementById('tabla_estilo'); 

        var newRow = tbl.insertRow(tbl.rows.length);
        var cell1 = newRow.insertCell(0);
        cell1.textAlign='center';
        cell1.innerHTML='<a href="#"><img src="images/edit.png" width="14" height="14" alt="Edit"/></a>'

        var cell2 = newRow.insertCell(1);
        cell2.textAlign='center';
        cell2.innerHTML='<a href="#" class="delete"><img src="images/delete.png" width="14" height="14" alt="Delete"/></a>'

        var cell3 = newRow.insertCell(2);
        cell3.textAlign='center';
        cell3.innerHTML=table[i].price;

        var cell4 = newRow.insertCell(3);
        cell4.textAlign='center';
        cell4.innerHTML=table[i].description;          
    }
}

And here’s how my form looks
alt text

  • 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-18T08:43:35+00:00Added an answer on May 18, 2026 at 8:43 am

    From the onclick handler for the delete button, you can traverse up to its <tr> and then get that row’s rowIndex property.

    So in the onclick:

    var node = this.parentNode;
    while( node && node.tagName !== 'TR' ) {
        node = node.parentNode;
    }
    
    var index = node.rowIndex;
    

    So when you’re setting up your row cells, you can add a handler:

    var cell2 = newRow.insertCell(1);
    cell2.textAlign='center';
    cell2.innerHTML='<a href="#" class="delete"><img src="images/delete.png" width="14" height="14" alt="Delete"/></a>'
    
    cell2.firstChild.onclick = function() {
        var node = this.parentNode;
        while( node && node.tagName !== 'TR' ) {
            node = node.parentNode;
        }
        var index = node.rowIndex;
        alert('index');
        return false;
    }
    

    This creates a new function for each row. It would be better to reference a named function instead.

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

Sidebar

Related Questions

I have a bit of problem with my function who just should return html
I have a bit of a problem. I am trying to do the following
I have a bit of a problem. I wrote an API a long time
I have a bit of a problem with user controls. Basically what I want
I have run in to a bit of a problem and I have done
I'm having a bit of a problem. I have a datatable in the parent
I'm having a bit of a problem here. We have 2 urls let me
I have run into a bit of a tricky problem in some C++ code,
Ok - a bit of a mouthful. So the problem I have is this
I have a bit of problem with this. I have a class A which

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.