Good day I'm working on a SELECT input which, according to the element, displays a different Radio Button group but I need the radiobutton not to be selected when it shows a new group, all radios are deselected and I want to do it with JavaScript.
Good day I'm working on a SELECT input which, according to the element, displays a different Radio Button group but I need the radiobutton not to be selected when it shows a new group, all radios are deselected and I want to do it with JavaScript.
Although when you start the page there is no one selected, once you have selected one you have to deselect them manually. Here is an example:
HTML
<input id="rad1" type="radio" name="grpRadio">
<input id="rad2" type="radio" name="grpRadio">
<input id="rad3" type="radio" name="grpRadio">
<input id="btnReset" type="button" value="Reset">
JS
var btnReset = document.getElementById("btnReset");
if (btnReset) {
btnReset.onclick = function () {
resetRadioButtons("grpRadio");
}
}
else {
alert("btnReset not found");
}
function resetRadioButtons(groupName) {
var arRadioBtn = document.getElementsByName(groupName);
for (var ii = 0; ii < arRadioBtn.length; ii++) {
var radButton = arRadioBtn[ii];
radButton.checked = false;
}
}
I hope it serves you.