JSFiddle - React, Tailwind, and code Playground
by procoib
HTML
<form id="checkit">
<p>Please select your preferred contact method:</p>
<div>
<input type="radio" id="contactChoice1"
name="contact" value="email">
<label for="contactChoice1">Email</label>
<input type="radio" id="contactChoice2"
name="contact" value="phone">
<label for="contactChoice2">Phone</label>
</div>
</form>
<br>
<div id="log">
</div>
JavaScript
var form = document.querySelector("form");
var log = document.getElementById("log");
form.addEventListener("click", () => {
var data = new FormData(form);
var output = "";
for (const entry of data) {
output = output + entry[0] + " = " + entry[1] + "\r";
};
log.innerText = output;
}, false);