title: javascript validation of radio buttons in a form
body: <p>hope someone can shed light on the below code which alerts always the error below. The code was devised to validate one radio button is selected otherwise return false to the current page otherwise proceed with the form action. Thanking in you in advance!!</p>
  
  <pre><code>  function onDisplayItemsForm(){
    var re = false;           // used to determine when a button is checked
    var radIdSelected = frmDisplayItems; 
  
  // traverse the radio buttons
  // if one is checked sets re to true, and stops the iteration
      for(var i=0; i&lt;radIdSelected.length; i++) 
      {
        if(radIdSelected[i].checked == true) 
        {
         re = true;
     break;
  
         }
  
     if (!radIdSelected[i].checked) 
  {
        alert("Please select product");
        return false;
      }
       return true;
  
    }
   };
  </code></pre>
  
  <p>The form is as follows:</p>
  
  <pre><code>  &lt;form name="frmDisplayItems" action="showItem.php" onsubmit="return onDisplayItemsForm();" &gt;
  
  
        &lt;table width="50%" border="1"&gt;
  
    &lt;th&gt;Country of Origin&lt;/th&gt;
    &lt;th&gt;Select&lt;/th&gt;
    &lt;/tr&gt;
  
  
           &lt;td&gt;&lt;input name=\"radId\" type=\"radio\" value=\"$id\" /&gt;&lt;/td&gt;
  
  
  
    &lt;/tbody&gt;
    &lt;/table&gt;
  
    &lt;p&gt;&lt;input name="btnSubmit" type="submit" value="Select"/&gt;  &lt;/p&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>&lt;</p>