I'm trying to get all the radio buttons by their names and check if they are blank. If one is blank, then form will show an alert and will not submit. If all buttons are filled then it will go to the "else" part and see whether the answer is correct. If it is correct, then it will show the right values in that page <div>
.
It goes to the "alert" but, even if I select the radio button, it does not go to else part.
What am I doing wrong?
$(document).ready(function() {
$("#btnDel").click(function() {
var count = 0;
if ($("input[name='ques1']").attr('checked', false) || $("input[name='ques2']").attr('checked', false)) {
alert("Please Fill all the Fields");
} else {
//question no 1
if ($("input[name='ques1']").attr('checked', false) || $("input[name='ques2']").attr('checked', false)) {
alert("Please Fill all the Fields");
} else {
if ($("input[name='ques1']:checked").val() == 6) {
count++;
$("#answerques1").text("Your Answer is correct");
} else {
$("#answerques1").html("<p style='color:red'>Your Answer is incorrect</p>");
}
//question no 2
if ($("input[name='ques2']:checked").val() == 4) {
count++;
$("#answerques2").text("Your Answer is correct");
} else {
$("#answerques2").html("<p style='color:red'>Your Answer is incorrect</p>");
}
}
}
});
});