Javascript. Creating A Dynamic Table Based On A User Input
I'm trying to ask the user through a prompt for a number that is an: integer, greater than 0, and is numeric. I did that with a do while loop and seems to be working correctly. Wit
Solution 1:
Two things:
You need to actually call the function after the prompt, so you need to add a line after your do while:
genTable(numChose);
That still won't work, since the DOM will not be ready (myTableDiv
will be undefined), so you need to wrap your entire code in an event listener:
document.addEventListener("DOMContentLoaded", function(event) {
//do work
});
Solution 2:
Move the <script>
code after the
<div id="mytable">
</div>
in <body>
so that the element is rendered on DOM while table is being generated and call the function
genTable(numChose);
after you get the number from user.
Post a Comment for "Javascript. Creating A Dynamic Table Based On A User Input"