title: Updating hidden input in HTML Form with Javascript
body: <p>I have an HTML form with a series of questions in 3 groups (A, B and C) and users can only answer the questions from either group. I have a script that validates their input to check that they have answered all the questions in one group only.</p>
  
  <p>I would like to capture which group of questions they answered and send that as a hidden input. I've setup a hidden input like this:</p>
  
  <pre><code>&lt;input type="hidden" name="type" value="" id="type"&gt;
  </code></pre>
  
  <p>and ideally I would like to replace this on submit withe something like:</p>
  
  <pre><code>&lt;input type="hidden" name="type" value="groupA" id="type"&gt;
  </code></pre>
  
  <p>I've setup a fiddle showing the form/script:</p>
  
  <p><a href="http://jsfiddle.net/fmdataweb/CGp8X/" rel="nofollow">http://jsfiddle.net/fmdataweb/CGp8X/</a></p>
  
  <p>and here's my current validation script:</p>
  
  <pre><code>$('#editRecord').on('submit', validate);
  $('input.sectionclear').on('click', function() {
      $(this).next().find('input').attr('checked', false);
  });
  function validate(ev) {
      var sectionsTouched = $('tbody').has(':checked'),
         inputs = {},
         errorMessage = '';
  
      if (sectionsTouched.length === 0) {
          errorMessage = 'Please check something before submitting.';
      } else if (sectionsTouched.length &gt; 1) {
          errorMessage = 'Please complete A or B or C only';
      } else {
          sectionsTouched.find('input').each(function(i, e) {
              var me = $(e), name = me.attr('name');
              inputs[name] = !!inputs[name] || me.is(':checked');
          });
          $.each(inputs, function(k, v) {
              if (!v) {
                  errorMessage = 'It appears you have not completed all questions.';
              }
              return v;
          });            
      }
      if (errorMessage !== '') {
          $('#error').html(errorMessage);
          ev.preventDefault();
          return false;
      }
      return true;
  }
  
  
  function seriesNames() {
      var names = [];
      $('h3').each(function(i, e) {
          names.push($(e).text());
      });
      return names;
  }
  
  function namesCommaDelimited(namesArr, conjunction) {
      var retval = '', i, l = namesArr.length - 1, delimiter = '';
      if (l === 0) {
         return retval;
      }
      for (i = 0; i &lt; l; i += 1) {
          retval += delimiter;
          retval += namesArr[i];
          delimiter = ', ';
      }
      retval += delimiter;
      retval += conjunction;
      retval += ' ';
      retval += namesArr[l];
      return retval;
  }
  ​
  </code></pre>
  
  <p>Is it possible to extend this in some way to capture which group of questions they answered? The HTML table has 3  tags to identify each of the groups:</p>
  
  <pre><code>&lt;tbody class="groupA"&gt;
  </code></pre>