Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Radio Button Check w/ jQuery

Tags:

html

jquery

What would be the best way to loop through all radio buttons on my page and alert the user if one of them is unchecked for a particular question?

Note: there are multiple questions on one page.

<li>
  <fieldset>
  <h3>What music do you listen to?</h3>  

        <ul class="answerList">
            <li>
                <input type="radio" id="choice_22" name="answer8" value="1" class=""/>
                <label for="choice_22" class="">Heavy Metal  </label>
            </li>
            <li>
                <input type="radio" id="choice_23" name="answer8" value="2" class=""/>
                <label for="choice_23" class="">Pop music</label>
            </li>
            <li>
                <input type="radio" id="choice_24" name="answer8" value="3" class=""/>
                <label for="choice_24" class="">Oh, a mix of stuff </label>
            </li>
         </ul>
       </fieldset>   
      </li>
like image 214
adam Avatar asked Dec 06 '22 07:12

adam


1 Answers

if (undefined === $("input[name='answer8']:checked").val()) {
    // do something
}
like image 186
patridge Avatar answered Dec 29 '22 22:12

patridge