Transforming my remarks into solutions for the purpose of providing examples
The standard method to retrieve the value is $("#radio").val()
Avoid having multiple radios with identical IDs. Each ID should be unique
All radios should share the same NAME attribute so triggering one will deselect the others
To obtain the value of the selected radio by name, use
$("[name=radio]:checked").val()
In this demonstration, duplicate IDs are intentionally left which results in only fetching the first value when accessed through ID
Encountering undefined is improbable in this configuration unless the script is executed before the radios are present
To account for scenarios where radios may not be available in the DOM during script execution, consider wrapping it in a load event handler
$(function() { // on page load
console.log($("#radio").val())
console.log($("#radio").attr("value"));
console.log($("[name=radio]:checked").val())
$("[name=radio]").on("click", function() {
console.log(this.value, $(this).val()); // either will work
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="radio" name="radio" type="radio" value="b" />
<input id="radio" name="radio" type="radio" value="a" checked/>