checking if at least one radio button has been selected – JavaScript

Something like this should do the trick

if ($("input[type=radio]:checked").length > 0) {
    // Do your stuff here
}

UPDATE
Did not see that it’s not supposed to have jQuery, so here’s an alternative function to check that in pure JS

 function check(){
     var radios = document.getElementsByName("choice");

     for (var i = 0, len = radios.length; i < len; i++) {
          if (radios[i].checked) {
              return true;
          }
     }

     return false;
 }

Leave a Comment