dimanche 26 octobre 2014

Making a table based of user input


Vote count:

0




I have written a javascript code which is



<html>
<head>
<style type="text/css">

#finalTable {
border: 1px solid black;
border-collapse: collapse;
}

</style>
</head>

<body>

<input type="number" id="arrayLength" />
<button id="myButton">Submit</button>
<table id="finalTable"></table>;

<script>

var tableData = ["<td>"];

function myFunction(){
var tableRow;
tableData.length = document.getElementById("arrayLength").value;
for(i=0; i<tableData.length; i++){
tableData[i] = "This is your table";
tableRow = "<tr>" + tableData[i] + "</tr>";
}

return tableRow;

}

document.getElementById("myButton").onclick = function(){
document.getElementById("finalTable").innerHTML = myFunction();
}

</script>

</body>

</html>


Here what I want, when a user input some number in field, it should create a table with same rows & with data "this is your table" in it. I mean if I input 5, it should make 5 rows & 5 columns with "this is your table" in each cell. Currently it's making only one cell. I know it's far away from desired output, but please help me. Thanks in advance.



asked 11 secs ago







Making a table based of user input

Aucun commentaire:

Enregistrer un commentaire