getElementById not playing nice with Radio Buttons
javascript
Solution
You should call `document.getElementById` after the document is loaded. Try executing your code like this:
window.onload = function() {
alert(getRadioValue());
}
Problem
I am guessing getElementById doesn't work with radio buttons when you want to get the value of it or to find out if it is checked? I say this because I did this: ``` <input id="radio1" type="radio" name="group1" value="h264" checked="checked" /> <input id="radio2" type="radio" name="group1" value="flv" /> ``` To get the value of the selected one I did this: ``` function getRadioValue() { if(document.getElementById('radio1').value=='h264'){ return 'h264'; } else{ return 'flv'; } } ``` However, firebug keeps telling me: ``` document.getElementById("radio1") is null [Break on this error] if(document.getElementById('radio1').checked==true){ ``` What am I doing wrong? Thanks all