title: Javascript - get the radio button index number
body: <p>**I have a php page with an array of option like this... and I need to get by javascript **the index of the selected option. Above I put the code of the javascript that is not working... Any help will be appreciated! </p>
  
  <pre><code> &lt;input type="radio" name="option[1]" value="1"&gt;
  &lt;input type="radio" name="option[1]" value="2"&gt;
  &lt;input type="radio" name="option[1]" value="3"&gt;
  &lt;input type="radio" name="option[1]" value="4"&gt;
  
  &lt;input type="radio" name="option[2]" value="1"&gt;
  &lt;input type="radio" name="option[2]" value="2"&gt;
  &lt;input type="radio" name="option[2]" value="3"&gt;
  &lt;input type="radio" name="option[2]" value="4"&gt;
  
  &lt;input type="radio" name="option[3]" value="1"&gt;
  &lt;input type="radio" name="option[3]" value="2"&gt;
  &lt;input type="radio" name="option[3]" value="3"&gt;
  &lt;input type="radio" name="option[3]" value="4"&gt;
  ...
  </code></pre>
  
  <p><strong>Can anyone help me?
  I am trying something like this but it didn´t work</strong></p>
  
  <pre><code>   &lt;script type="text/javascript"&gt;
  
      function validateForm(form) {
  
          for (var i = 0; i &lt; form.elements.length; i++ ) {
  
              if (form.elements[i].type == 'radio') {
                  if (form.elements[i].checked == true) {
                      if (form.elements[i].value  == 1 || form.elements[i].value == 6){
                          var comentario=document.getElementsByName('comentario[]'[i]);
                          var opcao = form.elements[i];
                          alert(clickedElm(opcao));
                          submitFlag = true;
                          if (comentario.value.length &lt; 100){
                              submitFlag=false;
                              alert(i);
                          }
                          return submitFlag;
                      }
  
                  }
              }
          }
  
      }
      function clickedElm(element)
      {
        var index = 0;
        for (var i = 0; document.forms[0].elements.length; i++)
        {
          if (document.forms[0].elements[i] == element)
          {
            index = i;
          }
        }
        return index;
      }
      &lt;/script&gt;
  </code></pre>