function saveFav() {
let checked = Array.from(document.querySelectorAll("input[type=radio]:checked")).map(e => e.id);
localStorage.setItem('checked', JSON.stringify(checked));
}
function setFav() {
const getChecked = JSON.parse(localStorage.getItem("checked"));
let radios = [...document.querySelectorAll("input[type=radio]")];
radios.forEach(e => {
e.removeAttribute("checked")
getChecked.forEach(id => {
if (e.id === id) {
e.setAttribute("checked", "checked");
}
})
});
}
<div><b>Favorite sport :</b>
<input type="radio" id="basketball" name="sport" value="basketball" checked="checked">
<label for="basketball">basketball</label>
<input type="radio" id="football" name="sport" value="football">
<label for="football">football</label>
<input type="radio" id="handball" name="sport" value="handball">
<label for="handball">handball</label><br>
</div>
<div><b>Favorite fruit :</b>
<input type="radio" id="banana" name="fruit" value="banana" checked="checked">
<label for="banana">banana</label>
<input type="radio" id="apple" name="fruit" value="apple">
<label for="apple">apple</label>
<input type="radio" id="pear" name="fruit" value="pear">
<label for="pear">pear</label>
<input type="radio" id="raspberry" name="fruit" value="raspberry">
<label for="raspberry">raspberry</label><br>
</div>
<div><b>Favorite ... :</b> other radios ...<br><br>
</div>
<input onclick="saveFav()" type="button" value="Save favorite">
<input onclick="setFav()" type="button" value="Load favorite">