Search code examples
jqueryradio-buttonjquery-selectors

How do I know which radio checked and which is not with jquery


I am working on php quiz-test script.

I need to know which selected and which is not.

all radios are inside form, they are creating by while.

var myRadio = $("#form1 input[type='radio']:checked").val();
alert(myRadio);

this just returns 1 value, I have to many radio inside form.

<label>

      <input type="radio" name="<?php echo $s_id; ?>" value="<?php echo $cid; ?>"  />
      <?php echo $answer; ?>
</label>

jsfiddle


Solution

  • var myRadio = $('input[name=myRadio]');
    var checkedValue = myRadio.filter(':checked').val();
    

    or

    $('input[name=radioName]:checked', '#myForm').val()