title: Javascript form validation checkbox and radio not working
body: <p>I have a form that I need to validate with javascript to make sure at least one checkbox and one radio is checked. I know it would probably be easier to use jQuery but I'm trying to accomplish this with pure javascript. Here is the code:</p>
  
  <pre><code>&lt;form name="bulbform" action="compute.php"  onsubmit=" return validateForm()" method="post"&gt;
  &lt;p&gt;Enter your name: &lt;input type="text" name="name" size="20"&gt;&lt;/p&gt;
  &lt;p&gt;&lt;strong&gt;Light Bulbs&lt;/strong&gt;&lt;/p&gt;
  &lt;label&gt;&lt;input type="checkbox" name="bulbs[]" value="2.39"&gt;Four 25-watt light bulbs for  $2.39&lt;/label&gt;&lt;br&gt;
  &lt;label&gt;&lt;input type="checkbox" name="bulbs[]" value="4.29"&gt;Eight 25-watt light bulbs for  $4.29&lt;/label&gt;&lt;br&gt;
  &lt;label&gt;&lt;input type="checkbox" name="bulbs[]" value="3.95"&gt;Four 25-watt long-life light bulbs $3.95&lt;/label&gt;&lt;br&gt;
  &lt;label&gt;&lt;input type="checkbox" name="bulbs[]" value="7.49"&gt;Eight 25-watt long-life light bulbs $7.45&lt;/label&gt;&lt;br&gt;
  &lt;p&gt;&lt;strong&gt;Payment Method&lt;/strong&gt;&lt;/p&gt;
  &lt;label&gt;&lt;input type="radio" name="cc" value="Visa"&gt;Visa&lt;/label&gt;&lt;br&gt;
  &lt;label&gt;&lt;input type="radio" name="cc" value="Master Card"&gt;Master Card&lt;/label&gt;&lt;br&gt;
  &lt;label&gt;&lt;input type="radio" name="cc" value="Discover"&gt;Discover&lt;/label&gt;&lt;br&gt;
  &lt;p&gt;&lt;input type="submit" value="Order" /&gt; &lt;input type="reset" value="Clear form"/&gt;&lt;/p&gt;&lt;/form&gt;
  </code></pre>
  
  <p>Here is my javascript</p>
  
  <pre><code>  var radios = document.getElementsByTagName('input');
    var value;
    for (var i = 0; i &lt; radios.length; i++) {
      if (radios[i].type === 'radio' &amp;&amp; radios[i].checked) {
        // get value, set checked flag or do whatever you need to
        value = radios[i].value;
        alert(value);
        return true;
      }
      else{
        alert("You must select a payment method.")
        return false;
      }
  </code></pre>
  
  <p>With the else removed I'm able to show the credit card selected but when I add the else it always says you must select a payment method and is never true... Thanks ahead of time for any advice you can give. </p>