how to keep selected radio button based on id code example Example: get radio button value javascript document.querySelector('input[name="rate"]:checked').value;