title: Selecting random radio button using JavaScript
body: <p><strong>Objective</strong></p>
  <p>I'm using Alchemer (formerly SurveyGizmo) to create a survey.
  To properly route my participants I need to create a hidden question with radio buttons (single choice) in combination with a JavaScript action that selects one of the radio buttons randomly. The JavaScript should execute automatically when the page was loaded.</p>
  <p><strong>What I did</strong></p>
  <p>I searched stackoverflow and the internet, found a couple JSFiddles that did similar things, tried reverse engineering a solution for me, but it wont work.</p>
  <p>I have zero education regarding programming languages, just going with the little that I think I understand from looking at other peoples work.</p>
  <p>Using &quot;Inspect Element&quot;, I see that my radio buttons all have the class 'sg-input sg-input-radio&quot;, so I try collecting them using getElementsByClassName, not even sure if this is the way to approach this.</p>
  <p>Here is what I got so far</p>
  <pre><code>$(document).ready(function(){
      var array = document.getElementsByClassName('sg-input sg-input-radio');
      var winnerButton;
      var numberOfButtons = array.length;
  
    
    function SelectRadio() {
      
      var randomNumber = Math.floor(Math.random() * numberOfButtons);
      
      winnerButton = array[randomNumber];
      
      winnerButton.checked = true;
     
      }
    
  SelectRadio();
    
  }
  </code></pre>
  <p>When the page loads, no radio button is selected.</p>
  <p>I somehow feel like I'm close to having it work, but I need someone who knows what they're doing.</p>
  <p>Cheers and thank you for taking the time!</p>