I have two radio buttons within an HTML form. A dialog box appears when one of the fields is null. How can I check whether a radio button is selected?
With jQuery, it'd be something like
if ($('input[name=gender]:checked').length > 0) {
// do something here
}
Let me break that down into pieces to cover it more clearly. jQuery processes things from left to right.
input[name=gender]:checked
If you want to avoid this altogether, mark one of the radio buttons as checked (checked="checked"
) in the HTML code, which would guarantee that one radio button is always selected.