well like many things this has a variable answer... but what I think you will need to do is write a script that gets the correct answer (I would use ajax calls to server so the answer can not be seen in the browser code) then set an event on the submit button that cycles through your radio buttons for the correct answer easiest way to do that is add a class to each and do something sorta like.. //outside a function (before your document.ready as well) var correctanswer; //somewhere set the value of correctanwser $('.your_class').each( function(){ var temp_val = $('.your_class').val(); var temp_id = $('.your_class').attrib('id'); if(temp_val=='selected'){ if(temp_id == correctanswer){ //code for correct answer here } else{ //code for wrong answer here } }
) On Jun 25, 2:35 pm, Matt Riley <mattrileyiph...@gmail.com> wrote: > I'm making a simple quiz using jquery and the validate plug-in. I > think I'm really close but just need a nudge over the last hump. :-) > > I have a radio button group that requires the user to select at least > one button. That part is working. However, what I want to do is also > check to see if the user selected a certain button (i.e. the correct > answer). Only if the correct answer is satisfied will the form then > validate and move on to the next quiz question. > > Here's my code so far. Any help is greatly appreciated. > > <script type="text/javascript"> > $.validator.setDefaults({ > submitHandler: function() { > alert("Submitted!"); > > } > }); > > $.metadata.setType("attr", "validate"); > > $(document).ready(function() { > $("#quiz_form").validate();}); > > </script> > > </head> > <body> > > <div id="main"> > > <form class="cmxform" id="quiz_form" method="get" action=""> > <fieldset> > <fieldset> > <label for="answer1"> > <input type="radio" id="answer1" value="1" > name="answers" > validate="required:true" /> > Answer 1 > </label> > <label for="answer2"> > <input type="radio" id="answer2" value="2" > name="answers" /> > Answer 2 > </label> > <label for="answer3"> > <input type="radio" id="answer3" value="3" > name="answers" /> > Answer 3 > </label> > <label for="answer4"> > <input type="radio" id="answer4" value="4" > name="answers" /> > Answer 4 > </label> > <label for="answers" class="error">Please select an > answer.</label> > </fieldset> > <input class="submit" type="submit" value="Check > Answers"/> > </fieldset> > </form> > </div> > > </body> > </html>