Hi,
I made a function whereby clicking a radio button will show a hidden radio button sub-group, and when it's unchecked, the radio button sub-group hides again and all the radios in the sub-group are made unchecked.
The problem is I don't know how to pass the 3rd parameter, 'custom' in this example, into the function.
HTML:
JAVASCRIPT:
If I hardcode the name of the input, it works. For example:
(i=0; i < parentForm.custom.length; i++)
parentForm.custom[i].checked = false
How can I pass the element name so it's variable inside the function?
Thanks in advance.
I made a function whereby clicking a radio button will show a hidden radio button sub-group, and when it's unchecked, the radio button sub-group hides again and all the radios in the sub-group are made unchecked.
The problem is I don't know how to pass the 3rd parameter, 'custom' in this example, into the function.
HTML:
Code:
<input type="radio" name="product" value="standard" onclick="showSubGroup(this,'customOptions','custom');" /> <input type="radio" name="product" value="custom" onclick="showSubGroup(this,'customOptions','custom');" /> <div id="customOptions" style="display:none"> <input type="radio" name="custom" value="1" /> <input type="radio" name="custom" value="2" /> <input type="radio" name="custom" value="3" /> </div>
Code:
function showSubGroup(selection,showHideItem,btnGroup) {
var parentForm = selection.form;
if (selection.value == "custom") {
document.getElementById(showHideItem).style.display = "block";
} else {
for (i=0; i < parentForm.btnGroup.length; i++) {
parentForm.btnGroup[i].checked = false;
}
document.getElementById(showHideItem).style.display = "none";
}
}
(i=0; i < parentForm.custom.length; i++)
parentForm.custom[i].checked = false
How can I pass the element name so it's variable inside the function?
Thanks in advance.
Comment