title: javascript function to validate radio buttons giving strange output.
body: <p>I'm developing a quiz that pulls data out of a mysql database, and displays the results as radio buttons. The radio buttons are populated based off of key=>value and generated via a simple forloop. This has been done many times, simple google searching and research will yield all the results needed to accomplish this. The issue that I'm having, or was having (before I decided to just do this with jquery) was when I submit the form it would execute the javascript function to validate whether a button has been selected, but when you select any option other than the first radio button you'd receive the same "make a selection" alert that you would if you had not selected any buttons. Selecting the first radio button would return true and execute the getCheckedValue function call.  It seems as though, the script only recognizes that I have one input type and doesn't understand to iterate through the rest of the buttons. I've refactored this function a dozen times, and still have no idea why this doesn't work. </p>
  
  <pre><code>&lt;?php
      foreach ($dataReturn as $j =&gt; $value){
         echo "&lt;input type='radio' class='answer' id='radiobtn' name='radiobtn' value='".$j."'&gt;" .$value." &lt;/input&gt;&lt;br/&gt;";
      }
  ?&gt;
  </code></pre>
  
  <p>Above is the loop that generates the radio buttons (just for reference, $dataReturn is the return value of a shuffled associative array. (Which is working as intended)
  When the submit button is clicked, it calls the below javascript function. </p>
  
  <pre><code>    function isNull(){
      var isChecked = false;
      var radiobutton = document.getElementsByName('radiobtn');
      for (var i=0; i &lt;= radiobutton.length; i++){
          if (radiobutton[i].checked){
              return true;
              var answer = radiobutton[i].value;
              getCheckedValue(answer);//using this just for testing selected value
          }else { 
          alert("Make a selection.");
          }
      return false;
      }
  }
  </code></pre>
  
  <p>I just can't figure out why this doesn't work. As stated above, using jquery this works perfectly. </p>