title: JavaScript Validate Select List
body: <p>I've spent days researching this (including looking at this site) and I don't understand how to do this.</p>
  
  <p>I'm trying to get the JavaScript to validate that something is selected other than the default blank selection.</p>
  
  <p>Every time the code gets to the select list it pops up with the window alert, but does not check if anything has been selected or not. Even if I have selected something the alert message pops up, and then continues the code so other error alerts pop up from fields not being filled out.</p>
  
  <p>I would like for it to know if something is selected. If it is then no error message for it. If there is nothing selected then I would like only this alert message to appear.</p>
  
  <p>Here is the Javascript function that has to do with this list (in the header)</p>
  
  <pre><code>function selectB() {
      x = 0;
  
      if (document.getElementById("mSQ").checked) {
          x++;
      }
  
      if (document.getElementById("pSQ").checked) {
          x++;
      }
  
      if (document.getElementById("cSQ").checked) {
          x++;
      }
  
      if (x == 0) {
          window.alert('You must select a Security Question');
          mSQ.focus();
          return false;
      }
  }
  </code></pre>
  
  <p>Here is the HTML </p>
  
  <pre><code>    &lt;p&gt;Please Select a Security Question from the Drop Down List.&lt;br /&gt;
      &lt;select name = "Security Question"&gt;
          &lt;option value = "d" id = "default" &gt;&lt;/option&gt;
          &lt;option value = "m" id = "mSQ" &gt;What is your Mother's maiden name?&lt;/option&gt;
          &lt;option value = "p" id = "pSQ" &gt;What is the name of your pet?&lt;/option&gt;
          &lt;option value = "c" id = "cSQ" &gt;What is your favorite color?&lt;/option&gt;
      &lt;/select&gt;&lt;/p&gt;
  </code></pre>
  
  <p>Please help, I've been stuck on this for so long.</p>