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?
A vanilla JavaScript way
var radios = document.getElementsByTagName('input'); var value; for (var i = 0; i < radios.length; i++) { if (radios[i].type === 'radio' && radios[i].checked) { // get value, set checked flag or do whatever you need to value = radios[i].value; } }