jquery - How to determine if radio buttons are checked? -


this question has answer here:

i'm trying radio buttons names , check if blank. if 1 blank, form show alert , not submit. if buttons filled go "else" part , see whether answer correct. if correct, show right values in page <div>.

it goes "alert" but, if select radio button, not go else part.

what 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 fields");     } else {       //question no 1                                  if ($("input[name='ques1']").attr('checked', false) || $("input[name='ques2']").attr('checked', false)) {         alert("please fill fields");       } else {         if ($("input[name='ques1']:checked").val() == 6) {           count++;           $("#answerques1").text("your answer correct");         } else {           $("#answerques1").html("<p style='color:red'>your answer incorrect</p>");         }         //question no 2         if ($("input[name='ques2']:checked").val() == 4) {           count++;           $("#answerques2").text("your answer correct");         } else {           $("#answerques2").html("<p style='color:red'>your answer incorrect</p>");         }       }     }       }); }); 

you can use .is(':checked') check if radio button checked or not..

    if(!$("input[name='ques1']").is(':checked')  || !$("input[name='ques2']").is(':checked')){     // both not checked     }  

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -