Amit Dhamu

Writes Code

Check If Radio Button Has Been Checked

Say you have a series of radio buttons on one page and for each group (with the same name), you want to ensure that at least one value has been selected. With jQuery you can.

var elements = {};
var count = 0;

$(':radio').each(function() {
    elements[$(this).attr('name')] = true;
});

$.each(elements, function() {
    count++;
});

if($(':radio:checked').length === count) {
    // All radio groups have a value selected
} else {
    // There is a radio button group with an empty value
}


form / radio / jquery

← Open External Links In New Tab MySQL to CSV Export →