JSFiddle - React, Tailwind, and code Playground
HTML
<p>
<label><input name="fruit" type="radio" value="apple" /> Apple</label><br />
<label><input name="fruit" type="radio" value="cherry" /> Cherry</label>
</p>
<p>
<button id="my_btn">Which Fruit?</button>
</p>
JavaScript
function checkFruit(){
var fruit_radio_pointers = document.getElementsByName("fruit");
var which_fruit = null;
for(var i=0; i<fruit_radio_pointers.length; i++){
if(fruit_radio_pointers[i].checked){
which_fruit = fruit_radio_pointers[i].value;
break;
}
}
alert(which_fruit);
}
document.getElementById("my_btn").addEventListener("click", checkFruit, false);