getElementById: is returning returning "null"

hi all - i noticed that i could not get html elements so i implemented this simple snippet and variations on it:

var elem = document.getElementById("myradio");

problem is that elem value is “null” for various widgets i have tried. i have tried to enumerate id values for more complex widgets (by extracting and displaying “id” attribute of all html elements in the document) but they are all “null”.

also, when i reference the element in a statement ie. $$(“elem”), i get an error message: “Type Error: elem is null”.

is there something i am doing wrong here?

sorry the snippet should be:
input type=“radio” id=“myradio” name=“Color” value=“Blue”
var elem = document.getElementById(“myradio”);

NB. opening/closing angle brackets have been removed because this discussion forum text editor removes anything between angle brackets when you post a comment

This error TypeError: document.getelementbyid(…) is null would seem to indicate that there is no such element with an ID passed to getElementById() exist. This can happen if the JavaScript code is executed before the page is fully loaded, so its not able to find the element. The solution is that you need to put your JavaScript code after the closure of the HTML element or more generally before < /body > tag.

http://net-informations.com/js/iq/error.htm