Kod
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
</head>
<body>
<form>
<input class="a1" name="wybor" type="radio" value="tak" /> Tak
<input class="a1" name="wybor" type="radio" value="nie" /> Nie
<input class="a1" name="wybor" type="radio" value="nie wiem" /> Nie wiem
<br />
<input id="b1" type="button" value="Pokaż wybór" /> <br />
<span id="wynik"></span>
</form>
<script>
const b1 = document.querySelector("#b1");
const wynik = document.getElementById("wynik");
b1.onclick = function () {
const radio = document.querySelectorAll('input[name="wybor"]');
console.log(radio);
let wybrano = "Nic nie wybrano";
for (const aa of radio) {
if (aa.checked) {
wybrano = aa.value;
break;
}
}
wynik.innerHTML = wybrano;
};
</script>
</body>
</html>