Radio Button Validation

Just thought I’d share the latest version of my function for validating radio buttons.

var radioValidate = function(nam) {
return [].slice.call(document.getElementsByName(nam)).some(function(a) {return a.checked;});
}

Simply call the function specifying the name for the group to be validated and the function will return true if a button in the group is selected.

If your visitors still use antiquated browsers you might need a polyfill to add support for some of the newer JavaScript commands to those browsers but the number of people using such old browsers is falling so even if you do need a polyfill you may not need it for long.