Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DeleteRow() not working 2

Status
Not open for further replies.

cdw0308

Technical User
Oct 8, 2003
181
US
I have two functions addrow() and deleterow(i)
The delete row function works for the first row on the table and then will not delete any others.
The addrow function works everytime.

Here is my code. Any help would be greatly appreciated..

Code:
<script language="javascript"> 
function deleteRow(i)
{
document.getElementById('table1').deleteRow(i)
}
function addRow() 
{ 
var tbody = document.getElementById("table1").getElementsByTagName("tbody")[0]; 
var row = document.createElement("TR"); 
var cell1 = document.createElement("TD"); 
var inp1 =  document.createElement("INPUT"); 
inp1.setAttribute("type","text"); 
inp1.setAttribute("value",""); 
cell1.appendChild(inp1); 
var cell2 = document.createElement("TD"); 
var inp2 =  document.createElement("INPUT"); 
inp2.setAttribute("type","text"); 
inp2.setAttribute("value",""); 
cell2.appendChild(inp2); 
var cell3 = document.createElement("TD"); 
var inp3 =  document.createElement("INPUT"); 
inp3.setAttribute("type","text"); 
inp3.setAttribute("value",""); 
cell3.appendChild(inp3);
var cell4 = document.createElement("TD"); 
var inp4 =  document.createElement("INPUT"); 
inp4.setAttribute("type","button"); 
inp4.setAttribute("value","Delete"); 
inp4.setAttribute("onClick", "deleteRow(this.parentNode.parentNode.rowindex)");
cell4.appendChild(inp4);

row.appendChild(cell1); 
row.appendChild(cell2); 
row.appendChild(cell3); 
row.appendChild(cell4);
tbody.appendChild(row); 

//alert(row.innerHTML); 
} 
</script>

Code:
<table id="table1"> 
<tbody> 
<tr> 
<td><input type="text" value=""></td> 
<td><input type="text" value="" width="10"></td> 
<td><input type="text" value="" width="10"></td> 
<td><input type="button" value="Delete" onclick="deleteRow(this.parentNode.parentNode.rowIndex)"></td>
</tr> 
</tbody> 
</table> 
<input type="button" value="Insert Row" onClick="addRow();">
 
I have also problems with DeleteRow()...

I have:

tr = document.createElement('tr');
td = document.createElement('td');
td.className='bottomline';

inpDel = document.createElement('INPUT');
inpDel.setAttribute('type','button');
inpDel.setAttribute('value','Delete_r');
inpDel.onclick = function()
{
document.getElementById('tablename').deleteRow(this.parentNode.parentNode.rowIndex);
}
inpDel.style.height = 22;
td.appendChild(inpDel);


td.innerHTML += ' more text';//this line make the script doesn't work.


inpButt = document.createElement('INPUT');
inpButt.setAttribute('type','text');
inpButt.setAttribute('value','some text brrrr...');
inpButt.style.width='225px';
td.appendChild(inpButt);

tr.appendChild(td);

ewerythink is ok, bu when i want to add lines:
td.innerHTML += ' more text';
script doesn't want to delete row...

Hov can I add some text to this cell...?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top