Demo: Radio Button Validation

Click Submit with no option selected to see the validation message. Then choose an option and submit again.

Gender
Click the submit button to validate the group.

JavaScript Used in This Demo Top ↑

const selected = document.querySelector('input[name="gender"]:checked');
if (!selected) {
  message.textContent = "Please select one radio button before submitting.";
  return;
}
message.textContent = `Validation passed. Selected value: ${selected.value}`;

HTML Used in This Demo Top ↑

<label><input type="radio" name="gender" value="male"> Male</label>
<label><input type="radio" name="gender" value="female"> Female</label>
<button type="submit">Submit</button>

Radio button validation tutorial




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer