I my application “When a button is clicked it should create a new text field in the table”. So i have done like this and its not working as well. So what could be the problem in the following snippet.
<html>
<script type="text/javascript" language="javascript">
var newtr=document.createElement("tr");
var newtd=document.createElement("td");
var output="<input type=\"textfield\"";
newtd.innerHtml=output;
newtr.appendChild(newtd);
function create_row()
{
document.getElementById("table1").appendChild(newtr);
}
</script>
<body>
<table id="table1">
<tr>
<td>
<input type-"textfield" name="tfield">
</td>
</tr>
<tr>
<td> <input type="button" name="button" value="new row" onclick="create_row();">
</tr>
</table>
</body>
</html>
I am using IE7.
Few remarks about your code:
var output="<input type=\"textfield\""is not validtype="textfield"definedinnerHTMLand notinnerHtmltrelement every time the button is clicked, so this should be inside thecreate_rowfunction<input type-"textfield" name="tfield">. This should be changed to<input type="text" name="tfield" />headsection in your documentI’ve tried cleaning your code a bit:
UPDATE:
As pointed out by Guffa and Serkan answers in IE7 a
tbodysection needs to be used: