Check If a Radio Button Is Checked with JavaScript

Web Design & Web Development

In this article, I will introduce how to check if a radio button is checked with JavaScript.

The checked Property

To check if a radio button is checked, the JavaScript checked property.

This property returns a Boolean value indicating whether the radio button was checked.
If the radio button was checked, it returns true, otherwise it returns false.

The example is below.

const isChecked = element.checked; // true|false

Demo

Sponsored links

Code

HTML

<form>
  <input type="radio" id="radioBtn">
  <label for="radioBtn">Web Designer</label>
  <button id="btn">Check</button>
</form>

JavaScript

const btn = document.getElementById('btn');
const rb = document.getElementById('radioBtn');

btn.addEventListener('click', () => {
  if (rb.checked) {
    alert("Checked");
  } else {
    alert("Unchecked");
  }
});