views:

1603

answers:

1

I have a basic quiz/survey type application I'm working on, and I'd like to give the user a prompt before they submit if they haven't answered all the questions. All the questions are multiple choice using radio buttons:

<div class="question">
    Q1: What is the second letter of the alphabet?
    <div class="choices">
        <input type="radio" name="question_1" value="1" /> A
        <input type="radio" name="question_1" value="2" /> B
        <input type="radio" name="question_1" value="3" /> C
    </div>
</div>
<div class="question">
    Q2: Which out of these is a berry?
    <div class="choices">
        <input type="radio" name="question_2" value="1" /> Apples
        <input type="radio" name="question_2" value="2" /> Bananas
        <input type="radio" name="question_2" value="3" /> Carrots
    </div>
</div>
<div class="question"> ...etc

How do you find which groups haven't got an option ticked? Or at least, if there are any which haven't been answered?

jQuery is ok, and even preferred.

+5  A: 

Ah, I figured it out:

$('div.question:not(:has(:radio:checked))')
nickf
+1 for a surprisingly concise selector.
eyelidlessness
gotta love jQuery...
nickf