Sometimes, we want to get value of selected radio button with JavaScript.
In this article, we’ll look at how to get value of selected radio button with JavaScript.
How to get value of selected radio button with JavaScript?
To get value of selected radio button with JavaScript, we use querySelector
.
For instance, we write
const value = document.querySelector('input[name="rate"]:checked').value;
to select the radio button with name rate
that’s selected with :checked
and querySelector
.
And we get its value
attribute value with value
.
Conclusion
To get value of selected radio button with JavaScript, we use querySelector
.