View Full Version : Form validating problem! (Radio button quiz)

11-10-2012, 08:23 PM
I have required fields at the bottom; email, name etc if some of these fields hasn't been filled it won't submit the form and gives the error for the incorrect answers in quiz. This far my validator works.

But if all the required fields at bottom are filled and answers are incorrect it still lets the form submit, so my problem is how to block the form submit if the answers are incorrect? Here's my script;

<script type="text/javascript">// <![CDATA[

$.extend($.validator.messages, {
required: "this is required",
email: "enter valid email"

$.validator.addMethod("equalValue", function(value, element, param) {
var elem_name = $(element).attr('name');
value = $('input:radio[name="'+elem_name+'"]:checked').val();
return(value == param);
}, 'Incorrect answear');

$(document).ready(function() {
ignoreTitle: true,
rules: {
gender: "required ",
quiz1: {required: true, equalValue: "A"},
quiz2: {required: true, equalValue: "A"},
quiz3: {required: true, equalValue: "C"},
quiz4: {required: true, equalValue: "B"},
quiz5: {required: true, equalValue: "C"},
quiz6: {required: true, equalValue: "B"},

// ]]></script>

I use jQuery validator.

Thanks in advance