Radio button validation is not quite working correctly
<p>I have a slight problem when it comes to validating my radio buttons. What suppose to happen is that if none of the radio buttons have been selected then it should come up with a message stating "click a radio button' and if a radio button is selected it should output the message 'radio button '+ btnNum + ' was selected'. </p>

<p>Instead what it is doing is that no matter if a radio button is selected or not it always displays the message 'click a radio button'. I have been trying to figure this out for ages but can't seem to find a solution. Can you see where I have went wrong here so that the right message is displayed depending if a radio button is selected or not?.</p>

<pre><code>&lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" /&gt;
        &lt;title&gt;Create a Session&lt;/title&gt;
        &lt;script type="text/javascript"&gt;

 function validation() {
                var errMsgContainerO = document.getElementById("radioAlert");
                var btnRad1O = document.getElementsByName("SessionNo");
                var isbtnRad1Checked = false;
                for(i=0; i &lt; btnRad1O.length; i++){
                    if(btnRad1O[i].checked){
                        isbtnRad1Checked = true;
                        var btnNum = i;
                        i = btnRad1O.length;
                    }
                }
                if(!isbtnRad1Checked) {
                   errMsgContainerO.innerHTML = 'Click a radio button';
                } else {
                    errMsgContainerO.innerHTML = 'radio button '+ btnNum + ' was selected';
                }
                return false;  //for demo purposes
            }

  &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;

&lt;form action="create_session.php" method="post" name="sessionform"&gt;
&lt;table&gt;
          &lt;tr&gt;
          &lt;th&gt;2: Number of Sessions :&lt;/th&gt;
          &lt;td class="sessionNo"&gt;&lt;input type="radio" name="sessionNo" value="1" /&gt;1&lt;/td&gt;
                  &lt;td class="sessionNo"&gt;&lt;input type="radio" name="sessionNo" value="2" /&gt;2&lt;/td&gt;
                  &lt;td class="sessionNo"&gt;&lt;input type="radio" name="sessionNo" value="3" /&gt;3&lt;/td&gt;
                  &lt;td class="sessionNo"&gt;&lt;input type="radio" name="sessionNo" value="4" /&gt;4&lt;/td&gt;
                  &lt;td class="sessionNo"&gt;&lt;input type="radio" name="sessionNo" value="5" /&gt;5&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;div id="radioAlert"&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
</code></pre>
