javascript - How to delete a table row on button click of corresponding row? -



javascript - How to delete a table row on button click of corresponding row? -

this code:

function deletehosttable(src) { var table = src.parentnode.parentnode.parentnode; if(table.rows.length > 1) { table.deleterow(src.parentnode.parentnode); } } function addhost(src) { var table = src.parentnode.parentnode.parentnode; var newrow = table.insertrow(table.rows.length-1); var cell = newrow.insertcell(newrow.cells.length); cell.innerhtml = '<input type="hidden" name = "vtieridh" value = "vtierid" />' cell = newrow.insertcell(newrow.cells.length); cell.innerhtml = '<img src="images/minus.gif" onclick="deletehosttable(this);return false;"/>'; cell = newrow.insertcell(newrow.cells.length); cell.classname = "pagetitle"; cell.innerhtml = '<input type = "text" value="hstst" />'; } </script> <html> <table id="host#1" index="1"> <tr> <td colspan="10"> <h2 align="left" class="pagetitle">sub business relationship hosts:</h2> </td> </tr> <tr> <input type="hidden" name="vtieridh" value="<%=vtierid %>" /> <td><button id="minus" onclick="deletehosttable(this);"/></td> <td class="pagetitle"><input type="text" value="hstst" /></td> </tr> <tr> <td><button onclick="addhost(this);"></td> </tr> </table> </html>

now, when click button corresponding button, code deletes uppermost row , not row corresponding button clicked. how can delete row corresponding button in row?

just alter remove function to

function deletehosttable(src) { var row = src.parentnode.parentnode; row.parentnode.removechild(row); }

the reason it's not working deleterow expects index of row passed while passing object.

javascript

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -