How to get radio button value using JavaScript?

Radio element is one of the important elements in most HTML forms. It gives the flexibility to choose one option out of many options. It becomes tricky to get the selected value from the radio element. If we use JavaScript library jQuery then it becomes relatively easy.

Radio elements:

<input type="radio" name="Gender" value="Male" /> Male <br />
<input type="radio" name="Gender" value="Female" /> Female<br />

jQuery code:


If we want to limit the selection inside a form we can do the following:

jQuery code:


Get the value of the selected radio button