Karl Boyle Karl Boyle - 1 month ago 21
Javascript Question

Populate html table onload from javascript

I was following an example source code I found for populating a html table from javascript.
However there is a disconnect in my knowledge. The javascript is inside a populateTable function to find an element and create the other elements for the table and populate it from an array.

I don't want this to be done from a button click but when the screen loads.

So lets say...

<h1>Products</h1>
<p>List of products below:</p>
<table> <--- how do I tell this table to be populated from my populateTable function
</table>


Any feedback is appreciated!

EDIT: - I'm clearly learning javascript :) Trying to do core javascript.

Answer
<body onload="Javascript:populateTable()">  
    <div id="productTable">
    </div>
</body>

Stick this into your html pane, the body will run your function on load and get the desired result.