title: Randomly select all form fields values and fill out form - JS or jQuery - Not sure which
body: <p>I have a form and for testing I want to have a button to automatically fill out all fields randomly in each group, for checkboxes and radios just select one randomly from each group type deal. Most of the forms are quite large and for testing purposes it's getting to be a pain in the butt to select items all the time.</p>
  
  <p>An example of the form is:</p>
  
  <pre><code>&lt;div class="rows"&gt;&lt;b&gt;Education&lt;/b&gt;&lt;br&gt;
  &lt;select name="edu" id="edu" validate="required:true"&gt;&lt;option value=""&gt;Select One&lt;/option&gt;
  &lt;option value="Some High School"&gt;Some High School&lt;/option&gt;
  &lt;option value="High School graduate"&gt;High School graduate&lt;/option&gt;
  &lt;option value="Some college"&gt;Some college&lt;/option&gt;
  &lt;option value="College graduate"&gt;College graduate&lt;/option&gt;
  &lt;option value="Master’s degree"&gt;Master’s degree&lt;/option&gt;
  &lt;option value="Doctorate"&gt;Doctorate&lt;/option&gt;
  &lt;/select&gt;&lt;/div&gt;
  
  &lt;div class="rows"&gt;&lt;b&gt;Payor status&lt;/b&gt;&lt;br&gt;
  &lt;select name="payor" id="payor" validate="required:true"&gt;&lt;option value=""&gt;Select One&lt;/option&gt;
  &lt;option value="Medicare/Medicaid"&gt;Medicare/Medicaid&lt;/option&gt;
  &lt;option value="Insurance"&gt;Insurance&lt;/option&gt;
  &lt;option value="Self Pay"&gt;Self Pay&lt;/option&gt;
  &lt;/select&gt;&lt;/div&gt;&lt;br&gt;
  
  &lt;div class="rows"&gt;&lt;b&gt;I am a physician.&lt;/b&gt;&lt;br&gt;
  &lt;input type="hidden" name="type33-8" value="YN"&gt;
  &lt;label&gt;&lt;input type="radio" name="33-8" id="33Y" value="Yes" validate="required:true"&gt; Yes&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="33-8" id="33N" value="No"&gt; No&lt;/label&gt;&lt;br&gt;
  &lt;label for="33-8" class="error"&gt;Please select an option&lt;/label&gt;&lt;/div&gt;&lt;b&gt;This doctor:&lt;/b&gt;&lt;br&gt;
  &lt;input type="hidden" name="type34" value="6PMultiple"&gt;
  
  &lt;div class="rows"&gt;&lt;label&gt;1.     Appears sincere.&lt;/label&gt;&lt;br&gt;
  &lt;input type="hidden" name="type34-247" value="6PMultiple"&gt;
  &lt;label&gt;&lt;input type="radio" name="34-247" id="341" value="1" validate="required:true" &gt; 1 - Very Strongly Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-247" id="342" value="2" &gt; 2 -  Strongly Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-247" id="343" value="3" &gt; 3 -  Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-247" id="344" value="4" &gt; 4 -  Agree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-247" id="345" value="5" &gt; 5 -  Strongly Agree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-247" id="346" value="6" &gt; 6 -  Very Strongly Agree&lt;/label&gt;&lt;/div&gt;
  
  &lt;div class="rows"&gt;&lt;label&gt;2.     Is professional.&lt;/label&gt;&lt;br&gt;
  &lt;input type="hidden" name="type34-248" value="6PMultiple"&gt;
  &lt;label&gt;&lt;input type="radio" name="34-248" id="341" value="1" validate="required:true" &gt; 1 - Very Strongly Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-248" id="342" value="2" &gt; 2 -  Strongly Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-248" id="343" value="3" &gt; 3 -  Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-248" id="344" value="4" &gt; 4 -  Agree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-248" id="345" value="5" &gt; 5 -  Strongly Agree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-248" id="346" value="6" &gt; 6 -  Very Strongly Agree&lt;/label&gt;&lt;/div&gt;
  
  &lt;div class="rows"&gt;&lt;label&gt;3.     Speaks clearly.&lt;/label&gt;&lt;br&gt;
  &lt;input type="hidden" name="type34-249" value="6PMultiple"&gt;
  &lt;label&gt;&lt;input type="radio" name="34-249" id="341" value="1" validate="required:true" &gt; 1 - Very Strongly Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-249" id="342" value="2" &gt; 2 -  Strongly Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-249" id="343" value="3" &gt; 3 -  Disagree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-249" id="344" value="4" &gt; 4 -  Agree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-249" id="345" value="5" &gt; 5 -  Strongly Agree&lt;/label&gt; 
  &lt;label&gt;&lt;input type="radio" name="34-249" id="346" value="6" &gt; 6 -  Very Strongly Agree&lt;/label&gt;&lt;/div&gt;
  </code></pre>
  
  <p>I had thought of running through all form elements:</p>
  
  <pre><code>for ( var i=0; i &lt; document.form1.elements.length; i++ ) {
      if ( document.form1.elements[i].type == "radio" ) {
          //Something
      }
  }
  </code></pre>
  
  <p>My problem is that goes through each and every element, that would work for the select dropdowns (although not sure how to randomly select one of the dropdowns options once there), but that wouldn't work for the radio's name groups.</p>
  
  <p>I had thought that for selecting dropdown options I could run this:</p>
  
  <pre><code>Math.random() * (max - min) + min
  </code></pre>
  
  <p>After getting the options count to randomly select one using the integer returned, I don't know if that will work yet since I haven't tested it since I'm stuck on the radio problem.</p>