title: How to get the selected radio button’s value?
body: <p>I’m having some strange problem with my JS program. I had this working properly but for some reason it’s no longer working. I just want to find the value of the radio button (which one is selected) and return it to a variable. For some reason it keeps returning <code>undefined</code>.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>function findSelection(field) {
      var test = 'document.theForm.' + field;
      var sizes = test;
  
      alert(sizes);
          for (i=0; i &lt; sizes.length; i++) {
              if (sizes[i].checked==true) {
              alert(sizes[i].value + ' you got a value');     
              return sizes[i].value;
          }
      }
  }
  </code></pre>
  
  <p><code>submitForm</code>:</p>
  
  <pre><code>function submitForm() {
  
      var genderS =  findSelection("genderS");
      alert(genderS);
  }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form action="#n" name="theForm"&gt;
  
      &lt;label for="gender"&gt;Gender: &lt;/label&gt;
      &lt;input type="radio" name="genderS" value="1" checked&gt; Male
      &lt;input type="radio" name="genderS" value="0" &gt; Female&lt;br&gt;&lt;br&gt;
      &lt;a href="javascript: submitForm()"&gt;Search&lt;/A&gt;
  &lt;/form&gt;
  </code></pre>