title: JavaScript function checked if a radio button is selected
body: <pre><code>&lt;label for="Merital Status"&gt;Marital Status:&lt;/label&gt;
      &lt;input type="radio" title="Marital Status" name="Marital_Status" id="Marital Status" value="Single"/&gt;Single
      &lt;input type="radio" title="Marital Status" name="Marital_Status" value="Married"/&gt;Married
      &lt;input type="radio" title="Marital Status" name="Marital_Status" value="Divorced"/&gt;Divorced
  </code></pre>
  
  <p>And I want to write a JavaScript function that checks whether a radi button named "Merital_Status" is selected. I represent the function that I wrote for this purpose. The function gets as an argument the element id and returnes boolen:</p>
  
  <pre><code>function radio_button_checker(elemId)
  {
      var radios = document.getElementsByTagName(elemId);
  
      var value = false;
  
  
      for (var i = 0; i &lt; radios.length; i++) 
      {
  
          if (radios[i].checked) 
          {
  
              value = true;
              break;
          }
      }
      return value;
  }
  </code></pre>
  
  <p>And I invoke this function like this:</p>
  
  <pre><code>if (radio_button_checker('Marital_Status') == false) 
  {
      alert('Please fill in your Merital Status!');
      return false;
  }
  </code></pre>
  
  <p>But it does not work. Please tell me how to modify my function in order to check if radiobutton is checked.</p>