Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2012, 08:23 PM   PM User | #1
Riku
New Coder

 
Join Date: Feb 2012
Location: Finland
Posts: 57
Thanks: 3
Thanked 9 Times in 9 Posts
Riku is an unknown quantity at this point
Form validating problem! (Radio button quiz)

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;

Code:
<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() {
$("#form").validate({
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
Riku is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:48 PM.


Advertisement
Log in to turn off these ads.