So I am creating a small online quiz application with jQuery and PHP…
The jquery part of it is when I click submit it “Validates” the answers and highlights the answer they chose and tells them if they got it right or wrong…the php part of it tallies up there score and if they got 4/5 right it sends an email to an admin to send them a free gift, if they get less then 4 correct they have the option to take it again…
my problem is sending the post data after the jquery validation, it is simply not working… here is snippet example I have tried…
quiz.submit(function () {
if (validateQues1() & validateQues2() & validateQues3() & validateQues4() & validateQues5() & validateQues6()) {
$.post('includes/validation.php');
return true;
} else {
return false;
}
});
And validateQues1 looks like this:
function validateQues1() {
var selectedAnswer = $('input[name=q1]:checked', '#quiz').val();
if (selectedAnswer == 'cartilage') {
answer1.addClass("correctAnswer");
$("#ques1 :radio:checked").before("Correct!");
} else {
$("#ques1 :radio:checked").parent().addClass("wrongAnswer");
$("#ques1 :radio:checked").before("Incorrect!");
}
}
thanks for any help in advance, it is greatly appreciated!
~skv
You’re using bit OR rather than logical OR.
UPDATE
Your
ValidateQuesfunction must have a return boolean value, like this:You MUST update all your
validateQuesfunction to returntrue/false.