Someone Someone - 1 month ago 6
jQuery Question

How do i know which radio button Has been Selected using Jquery

<input type="radio" id="radio1" name="rb1" value="no"> No
<input type="radio" id="radio2" name="rb1" value="yes"> Yes


when I say this
alert("Test =="+$('#radio1').attr('checked'));
I expect
false
because it's not checked but it returns
undefined
.

What is the correct statement?
Why am I getting
undefined
?

Answer

This post explains your exact problem: http://forum.jquery.com/topic/checking-if-certain-radiobutton-is-checked

i.e. you need to use this: alert($('#radio1').is(':checked'));