document.querySelector('input[name="rate"]:checked').value;
//html
<input type="radio" name="someName" value="value1">
<label>value1</label>
<input type="radio" name="someName" value="value2">
<label>value2</label>
//js
const radioButtons = document.querySelectorAll('input[name="someName"]');
var selectedRadioButton;
for (const radioButton of radioButtons) {
if (radioButton.checked) {
selectedRadioButton = radioButton.value;
break;
}
}
//now you have the value selected in selectedRadioButton
const selectedColor = document.querySelector('input[name="color"]:checked').value;
document.querySelectorAll('input[name="gender"]:checked').value;
<!DOCTYPE html>
<html>
<body>
<p>Retrieve Get radio button selected value using JavaScript</p>
<p>Select the gender:</p>
<input type="radio" name="Gender" onclick="myFunction(this)" value="Male">Male<br>
<input type="radio" name="Gender" onclick="myFunction(this)" value="Female">Female<br>
<script>
function myFunction(Gender) {
alert(Gender.value);
}
</script>
</body>
</html>