javascript - How to get value of selected radio button? -


i looked everywhere , tried selected value group of radio buttons.

here's html:

<div id="rates">   <input type="radio" id="r1" name="rate" value="fixed rate"> fixed rate   <input type="radio" id="r2" name="rate" value="variable rate"> variable rate   <input type="radio" id="r3" name="rate" value="multi rate" checked="checked"> multi rate   </div> 

here's .js:

var rates = document.getelementbyid('rates').value; var rate_value; if(rates =='fixed rate'){     rate_value = document.getelementbyid('r1').value;  }else if(rates =='variable rate'){     rate_value = document.getelementbyid('r2').value;  }else if(rates =='multi rate'){     rate_value = document.getelementbyid('r3').value; }    document.getelementbyid('results').innerhtml = rate_value; 

i keep getting undefined.

var rates = document.getelementbyid('rates').value; 

the rates element div, won't have value. undefined coming from.

the checked property tell whether element selected:

if (document.getelementbyid('r1').checked) {   rate_value = document.getelementbyid('r1').value; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -