//must have a condition to select a value and
//then get the element of that value individually to set it to checked.
//-you can take the value in var or get it from an object for ex.
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="Gender" id="male" value="Male">
Male
</label>
<label class="form-check-label">
<input type="radio" class="form-check-input" name="Gender" id="female" value="Female">
Female
</label>
</div>
var targetOption='male'
if(targetOption=='female') document.getElementById("female").checked=true;
if(targetOption=='male') document.getElementById("male").checked=true;
<!DOCTYPE html>
<html>
<body>
<p>Set radio button value using JavaScript</p>
Married: <input type="radio" id="radiomarried">
Unmarried: <input type="radio" id="radioUnmarried">
<p>Click the "Try it" button to check the radio button.</p>
<button onclick="selectTheMariedButton()">Click if you are maried</button>
<button onclick="selectTheUnmariedButton()">Click if you are not maried</button>
<script>
function selectTheMariedButton() {
var x = document.getElementById("radiomarried");
x.checked = true;
alert("Married is selected");
}
function selectTheUnmariedButton() {
var y = document.getElementById("radioUnmarried");
y.checked = true;
alert("Unmarried is selected");
}
</script>
</body>
</html>
<!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>