Categories
JavaScript Answers

How to get the selected radio button’s value with JavaScript?

Spread the love

To get the selected radio button’s value with JavaScript, we get the value property.

For instance, we write

const value = document.querySelector('input[name="genderS"]:checked').value;

to select the checked radio button with name attribute genders and that it’s checked by calling querySelector with 'input[name="genders"]:checked'

Then we get its value with the value property.

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 *