I want to create a dynamic table using html and javascript where the user enters number of rows, and want all table cells to be of input type
function createTable() {
var a, b, tableElem, rowElem, colElem;
a = 7
b = 5
if (a == "" || b == "") {
alert("Please enter some numeric value");
} else {
tableElem = document.createElement('table');
for (var i = 0; i < a; i++) {
rowElem = document.createElement('tr');
for (var j = 0; j < b; j++) {
colElem = document.createElement('td');
colElem.appendChild(document.createTextNode(j + 1)); //to print cell number
rowElem.appendChild(colElem);
}
tableElem.appendChild(rowElem);
}
document.body.appendChild(tableElem);
}
I found this code, but how to make all cells of input type?
document.createElement('input')instead ofdocument.createTextNode()DocumentFragmentdeveloper.mozilla.org/en-US/docs/Web/API/DocumentFragment and append it to the body after looping :)