Search code examples
javascriptdomdelete-row

delete a row in html table using a hidden type and javascript


I have a table with HTML constructed using my servlet class. When trying to delete a row in this table using a javascript function I must first of all put different id to separate elements.and i resolove it with hidden type like that:

retour.append("<td>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\"  value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<button id=\"del\" name=\"del\"  type=\"button\" onClick=DeleteARow('+id_"+nomTab+"_"+compteur+"')>");
retour.append("<img src=icon_delete.gif />");
retour.append("</button>");
retour.append("</td>");

As you can see each element has a delete button. What i want to know how can i delete one row.

thinks.


Solution

  • function deleteRow(r)
    {
    var i = r.parentNode.parentNode.rowIndex;
    document.getElementById('myTable').deleteRow(i);
    }
    

    You should check out this dom page:

    http://www.w3schools.com/js/js_ex_dom.asp

    hope this helps.