How do I get the value of the selected radio button?
-
Suppose there are two radio buttons, how to display the value of the selected radio button in console.log () ?
<div> <input type="radio" name="gender" value="Человек"> <input type="radio" name="gender" value="Женщина"> <button>Отправить</button> </div>
P.S: In general, if you google this question, then the solutions there are some ugly, therefore
I asked this question, suddenly there is a way to do it somehow elegantly. Clean JS is desirable.JavaScript Aubrey Orr, May 2, 2019 -
document.querySelector('button').addEventListener('click', function() {
console.log(document.querySelector('[type="radio"]:checked').value);
});Victoria Olsen -
Instead of a diva, see the formData values for the submission eventAnonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!