How to validate multiple radio buttons jQuery

    to validation multiple radio buttons using jquery use following code

    HTML Code

    <form name="radiotest" id="sitefrm">
    <div class="genderoption">
      <label><input type="radio" name="gender" class="gender"> Male </label>
      <label><input type="radio" name="gender" class="gender"> Female </label>
    </div>
    <div class="joboption">
      <label><input type="radio" name="job" class="job"> jQuery Developer </label>
      <label><input type="radio" name="job" class="job"> Drupal Developer </label>
      <label><input type="radio" name="job" class="job"> Ruby Developer </label>
      <label><input type="radio" name="job" class="job"> Wordpress Developer </label>
    </div>
    <input type = "submit" name="submit" value="Submit">
    </form>

    Jquery Code

    <script type="text/javascript">
    $(document).ready(function() {
    $('#sitefrm').submit(function() {
              var ret = true;
              var errs = 0;
              if(!$("input.gender:checked").val()) { alert("Please select gender"); errs++; }
              if(!$("input.job:checked").val()) {alert("Please select your job"); errs++; }
              if(errs > 0) {
                ret = false;
              }
              return ret;
          });
    });

    Note: I have user "input.gender:checked" there we can also use "input[@name=gender]:checked" but i found first one more accurate
    </script>
    5
    Average: 5 (1 vote)