[Solved] Need to alert for unchecked radio buttons in jquery


First, radio buttons are used for when you want the user to only pick one at a time. So, I think you would rather use checkboxes, rather than radio buttons.

Having said that, I think the easiest way to achieve your goal with jQuery is to use the :not selector. This code will get you all checkboxes that are not selected:

var notChecked = $('input:not(:checked)')

Here’s a fiddle with demo: http://jsfiddle.net/nasuf96b/

Obviously there’s some error handling that would have to be done, but you get the idea.

Good luck.

Edit

I see now what you’re after. Check out this fiddle: http://jsfiddle.net/nasuf96b/1/.
It tells you if nothing in a group has been selected, which I take it is what you want to do.

$('input').on('click', function() {
    check_all();   
});

function check_all() {
    var outputText="These are not checked: ";
    var myDivs = $('div.radio');
    for (var i=0; i<myDivs.length; i++) {
        var isChecked = false;
        var childInputs = myDivs[i].getElementsByTagName('input');
        for (var j=0; j<childInputs.length; j++) {
            if (childInputs[j].checked == true) {
                isChecked = true;
            }
        }
        if (isChecked == false) {
            outputText += (i+1) +', ';   
        }
    }
    alert(outputText.slice(0, -2));
}

3

solved Need to alert for unchecked radio buttons in jquery