title: Accessing radio elements in forms in javascript
body: <p>I have a use case where the the number of radio buttons can be 1 or more, what is the best practice to check </p>
  
  <p>i.e </p>
  
  <pre><code>var radioElements = document.forms["formname"].elements["abc"];
  for(var i=0; i &lt; radioElements.length; i++) {
      if(radioElements[i].checked) {
          alert("blah..");
          break;
      }
  }
  </code></pre>
  
  <p>This works when the DOM has</p>
  
  <pre><code>&lt;form name="formname"&gt;
    &lt;input type=radio name=abc id=abc value=aaa/&gt;
    &lt;input type=radio name=abc id=abc value=bbb/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>But fails to work when it has only one radio element</p>
  
  <pre><code>&lt;form name="formname"&gt;
    &lt;input type=radio name=abc id=abc value=aaa/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>How can I make the above javascript work in both these cases.</p>