This is my first question on this awesome community.
I am using this javascript code to build a dynamic table:
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name = "chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "text";
element2.name = "txtbox[]";
element2.onkeypress = "this.style.width = ((this.value.length + 1) * 8) + 'px'";
cell2.appendChild(element2);
}
And following html code to print it:
<table id="dataTable" style="width: 300px;" border="0">
<tr>
<td ><input type="checkbox" name="chk" /></td>
<td <input id="txt" type="text" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';"> </td>
</tr>
</table>
My problem is that- I want my text input field to be dynamically expending, but due to using 'document.createElement("input");' in the Javascript, only the first text input field expends dynamically rest