title: Validating list box and radio button in javascript by ID
body: <p>Am trying to validate a listbox and Radio button using by ID, only on  onsubmit.
  if I ran in browser it is not showing any alert. When the submit button is clicked, I want to run the script to verify a radio and listbox is selected, if one is selected to do nothing. If one isn't selected I want it to post an alert message.</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
  
          function validate()
      {
          if (document.getElementById("drop1").value == "-1")
          {
              alert("please select A");
          }
          if (document.getElementById("drop2").value == "-1")
          {
              alert("please select B");
          }
          if (document.getElementById("drop3").value == "-1")
          {
              alert("please select C");
          }
          if (document.getElementById("drop4").value == "-1")
          {
              alert("please select D");
          }
          if (document.getElementById("drop5").value == "-1")
          {
              alert("please select E");
          }
  
              var radios = document.getElementsByName("A");
              var formValid = false;
  
              var i = 0;
              while (!formValid &amp;&amp; i &lt; radios.length) 
              {
                  if (radios[i].checked) formValid = true;
                  i++;        
              }
  
              if (!formValid) alert("Must check some option!");
              return formValid;
          }
  
      }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  A:&lt;select id="drop1"&gt;
  
      &lt;option value="1"&gt;item 1&lt;/option&gt;
  
      &lt;option value="2"&gt;item 2&lt;/option&gt;
  
      &lt;option value="3"&gt;item 3&lt;/option&gt;
  
      &lt;option value="4"&gt;item 4&lt;/option&gt;
  
      &lt;option value="0"&gt;All&lt;/option&gt;
  
  &lt;/select&gt;
   B:   &lt;select id="drop2" &gt;
  
      &lt;option value="1"&gt;item 1&lt;/option&gt;
  
      &lt;option value="2"&gt;item 2&lt;/option&gt;
  
      &lt;option value="3"&gt;item 3&lt;/option&gt;
  
      &lt;option value="4"&gt;item 4&lt;/option&gt;
  
      &lt;option value="0"&gt;All&lt;/option&gt;
  
  &lt;/select&gt;
  
  C:&lt;select id="drop3" &gt;
  
      &lt;option value="1"&gt;item 1&lt;/option&gt;
  
      &lt;option value="2"&gt;item 2&lt;/option&gt;
  
      &lt;option value="3"&gt;item 3&lt;/option&gt;
  
      &lt;option value="4"&gt;item 4&lt;/option&gt;
  
      &lt;option value="0"&gt;All&lt;/option&gt;
  
  &lt;/select&gt;
  
  D:&lt;select id="drop4" &gt;
  
      &lt;option value="1"&gt;item 1&lt;/option&gt;
  
      &lt;option value="2"&gt;item 2&lt;/option&gt;
  
      &lt;option value="3"&gt;item 3&lt;/option&gt;
  
      &lt;option value="4"&gt;item 4&lt;/option&gt;
  
      &lt;option value="0"&gt;All&lt;/option&gt;
  
  &lt;/select&gt;
  
  E:&lt;select id="drop5" &gt;
  
      &lt;option value="1"&gt;item 1&lt;/option&gt;
  
      &lt;option value="2"&gt;item 2&lt;/option&gt;
  
      &lt;option value="3"&gt;item 3&lt;/option&gt;
  
      &lt;option value="4"&gt;item 4&lt;/option&gt;
  
      &lt;option value="0"&gt;All&lt;/option&gt;
  
  &lt;/select&gt;
  &lt;input type="radio" id=myradio1 name="A" value="1"&gt;one
  &lt;input type="radio" id=myradio2 name="A" value="2"&gt;two
  &lt;input type="radio" id=myradio3 name="A" value="3"&gt;three
  &lt;input type="submit" value="submit" onclick="validate()"&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>