0

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.

Taobitz
  • 546
  • 3
  • 10
  • 22
  • 1
    You might find [window.onload vs document.onload](http://stackoverflow.com/questions/588040/window-onload-vs-document-onload) useful. – Andrew Morton Nov 05 '14 at 21:55
  • You can simply call directly http://www.w3schools.com/jsref/event_onload.asp – cesare Nov 05 '14 at 21:56

1 Answers1

2
<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.

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
user3821538
  • 117
  • 4