All pastes #518869 Raw Edit

Choogster

public php v1 · immutable
#518869 ·published 2007-05-29 13:29 UTC
rendered paste body
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Insert/Delete Table Row using DOM</title><script language="javascript">var gRowId = 2;function delRow(button){var row = button.parentNode.parentNode;var tbody = document.getElementById('table1').getElementsByTagName('tbody')[0];tbody.removeChild(row);}function addRow(){var tbody = document.getElementById('table1').getElementsByTagName('tbody')[0];var row = document.createElement('TR');var cell1 = document.createElement('TD');var cell2 = document.createElement('TD');var cell3 = document.createElement('TD');var inp1 =  document.createElement('INPUT');var inp2 = document.createElement('INPUT');inp1.setAttribute('type','text');inp1.setAttribute('name','usertxt');inp1.setAttribute('value','New row');inp2.setAttribute('type','button');inp2.setAttribute('value','Delete');inp2.onclick=function(){delRow(this);}cell1.innerHTML = gRowId;cell2.appendChild(inp1);cell3.appendChild(inp2);row.appendChild(cell1);row.appendChild(cell2);row.appendChild(cell3);tbody.appendChild(row);gRowId++;}</script></head><body><form name="myform" method="post" action="txtiterator.asp"><table id="table1"><tbody><tr><th>ID</th><th>Data</th><th>Action</th></tr><tr><td>1</td><td><input name="usertxt" type=text value="Original Row"></td><td><input type="button" value="Delete" onClick="delRow(this);" /></td></tr></tbody></table><input type="button" value="Insert Row" onClick="addRow();"><input type="submit" name="submit" value="Submit"></form></body></html>