I was trying to get selected radio button by using \"document.getElementByName(\'nameOfradio\')\" because all of the radio buttons share the same name. But, nothing happened
document.querySelector('input[name=nameOfRadio]:checked').value
Eg:-
Male Female Other document.querySelector('input[name=gender]:checked').value
Also, you can add a checked attribute to a default radio button among the group of radio buttons if needed
checked
Male Female Other