0

I use the below code to add or remove a row from a table using javascript. The code works fine on IE however it doesnt work on Firefox, can anybody suggest reasons why this might be doing so?

The id "table1" is the ID of the table I am trying to insert the innerhtml into.

Any help would be greatly appreciated.

Thanks

function addRoom()
{
	var row = document.all("table1").insertRow();
				
	var column = row.insertCell();
	column.innerHTML = "input type='text' name=txt1>";
				
	column = row.insertCell();
	column.innerHTML = "input type='text' name=txt2>";
				
	column = row.insertCell();
	column.innerHTML = "<input type='button' value='Delete' onClick='remove(this);' />";
				
						
}
			
function remove(src)
{
						
	var rowd = src.parentElement.parentElement;		
	
	document.all("table").deleteRow(rowd.rowIndex);		

}

Edited by ajwposh: n/a

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Kathiravan J
0

Please use this.

function addRoom()
{
    var row = document.getElementById("table1").insertRow(-1);
    var column = row.insertCell(-1);
    column.innerHTML = "input type='text' name=txt1>";
    column = row.insertCell(-1);
    column.innerHTML = "input type='text' name=txt2>";
    column = row.insertCell(-1);
    column.innerHTML = "<input type='button' value='Delete' onClick='remove(this);' />";
}

function remove(src)
{
    var rowd = src.parentElement.parentElement;     
    document.getElementById("table1").deleteRow(rowd.rowIndex);     
}

Edited by Reverend Jim: Fixed formatting

0

Kathiravan Jayachandran

I never reply to any blogs or post. This is the first time im replying. It is really good post and more helpful. I really thank you DOHYAH

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.