You can try using the code given below:
var rates = document.getElementById('rates').value;
In the above code, rates element is a div, hence it will not have a value. This is where the undefined is coming from.
Along with that, you can use checked property, it will tell you whether the element is selected or not:
if (document.getElementById('r1').checked) {
rate_value = document.getElementById('r1').value;
}