Categories
JavaScript Answers

How to get value of selected radio button with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *