I am a freshie in javascript and I am trying to make a table which depends on user input to add rows to a table
<!DOCTYPE html>
<html>
<head></head>
<body>
<table id="myTable">
<tr>
<td>New Cell</td>
<td>New Cell</td>
</tr>
</table>
<br/>
<button type="button" onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var input = window.prompt("Input number of rows", 1);
for (var i = 0 ; i < parseInt(input,10); i++) {
var table = document.getElementById("myTable").insertRow(i);
for (var j = 0; j < table.rows[i]; j++) {
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
}
}
}
</script>
</body>
</html>
Take Input from the user using javascript to add rows dynamically