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);		

}

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);     
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.