title: Using a repeatable Javascript function to validate multiple radio button groups
body: <p>I have looked through many different questions here (as well as through Google) and have not been able to find an answer which comes close to what I am looking for.</p>
  
  <p>I have a form (set up using tables) which has multiple radio button groups that I am trying to validate using JS. I know that I could write a function for each group which would accomplish the desired task however I am trying to simplify my JS script using as few functions as possible so here goes.</p>
  
  <p>I am trying to write a function that will check which radio button is selected and perform a different task depending on which selection is made. </p>
  
  <p><strong>HTML Code:</strong></p>
  
  <pre><code>    &lt;tr&gt;
          &lt;td class="left"&gt;&lt;span class="required"&gt;*&lt;/span&gt;Only approved Ingredients Used:&lt;/td&gt;
          &lt;td&gt;
              &lt;label&gt;&lt;input name="approve" type="radio" required id="approve_0" value="Yes"&gt;Yes&lt;/label&gt;
              &lt;label&gt;&lt;input name="approve" type="radio" required id="approve_1" value="No"&gt;No&lt;/label&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  
  <p>For each section like this (and I have around 15 of these sections) I am trying to us an "onChange="somefunction()" call which will result in an error message "(label name) must be completed" as well as cause a text box to appear for the user to input "corrective actions" in before submitting the form.</p>
  
  <p>Any help would be greatly appreciated</p>
  
  <p><em>I also would like to stay away from jquery</em></p>