i am appending a new row to the end of a table by using appendrow() , but it doesnt work , can anybody help me .
htm:
<body onload="makeTable()">
<table id= "tbl" border="1"></table>
<form>
<input type="button" value=" append a new row " onclick="appendRow()" /><br />
</form>
js:
function makeTable(){
var theTable =document.getElementById("tbl");
if (theTable.firstChild != null)
{
var badIEBody = theTable.childNodes[0];
theTable.removeChild(badIEBody);
}
var tBody = document.createElement("TBODY");
theTable.appendChild(tBody);
var newRow = document.createElement("tr");
var c1 = document.createElement("td");
var v1 = document.createTextNode("HIT6307");
c1.appendChild(v1);
newRow.appendChild(c1);
var c2 = document.createElement("td");
var v2 = document.createTextNode("Internet Technology");
c2.appendChild(v2);
newRow.appendChild(c2);
tBody.appendChild(newRow);
}
function appendRow() {
var code = prompt("What is the code of subject", "Type code here");
var name = prompt("What is the name of subject", "Type name here");
var tBody = document.getElementByTagName("TBODY");
newRow = document.createElement("tr");
c1 = document.createElement("td");
v1 = document.createTextNode("code");
c1.appendChild(v1);
newRow.appendChild(c1);
c2 = document.createElement("td");
v2 = document.createTextNode("name");
c2.appendChild(v2);
newRow.appendChild(c2);
tBody.appendChild(newRow);
tBody.appendChild(newRow);
}