Check “Enable gender choices” to activate the radio buttons. Clear it to disable the group again.
const toggle = document.getElementById("enableGender");
const radios = document.querySelectorAll('input[name="gender"]');
toggle.addEventListener("change", () => {
radios.forEach((radio) => {
radio.disabled = !toggle.checked;
});
});
<input type="checkbox" id="enableGender" name="others" value="yes"> Enable gender choices
<input type="radio" name="gender" value="male" disabled> Male
<input type="radio" name="gender" value="female" disabled> Female
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.