elements not loaded before onload event fired.

Permalink
I am creating a simple form in a Block and the <input...> elements are not yet loaded when it calls my initialization script. I get a js error, "TypeError: Slots is null". My lines of js code are:
Slots = document.getElementById("slots");
SlotsInput = Slots.getElementsByTagName("input");
These are pre-declared for global use in other functions. I have used all for onload event handlers and the only one that seems to almost work is the $(window).load() Jquery event handler. I don't get an error for the "Slots = ..." line. The console error message is showing the SlotsInput = Slots.getElementsByTagName("input") because the form is not loaded yet.

What am I missing ??????

ThomasJ