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:
$('input[name="name_of_your_radiobutton"]:checked').val();
If we want to limit the selection inside a form we can do the following:
jQuery code:
formObj.find("input[name=paymentMethod]:checked").val();