Yes/No Radio Button Groups that relate to the same fields showing/hiding
- August 17, 2022
- 1 reply
- 3189 views
Hi Everyone,
I wanted to share a form I am attempting to get working. Here's the scoop:
I have 2 radio groups. Each radio has a Yes or No radio button.
When "Question1" radio button "Yes" is selected, the "Field1" text field activates. If "No" is selected, it deactivates "Field1" providing "Question2" radio button is "No".
When "Question2" radio button "Yes" is selected, all three text fields activate. If "No" is selected, it deactivates "Field2" and "Field3", and "Field1" deactivates providing "Question1" radio button is "No".
Basically, "Field1" applies to both radio groups, and can only deactivate if both radio groups have "No" selected.
I'm trying to determine if the JavaScript I have is correct or if I've made any mistakes I'm not aware of. Or, if there is a better/simpler way to do what I'm attempting. If you look at the attached file, you can see the JavaScript I have applied to the radio buttons in Properties > Actions.
For "Question1", I have this JavaScript on the "No" button:
this.getField("Field1").display = display.hidden;
this.getField("Field2").display = display.hidden;
this.getField("Field3").display = display.hidden;
if (this.getField("Question1").valueAsString=="No" && this.getField("Question2").valueAsString=="Yes") {
this.getField("Field1").display = display.visible;
} else {
this.getField("Field1").display = display.hidden;
}
I had to add the 3 fields before the if "Question1" is set to "No" and "Question2" is set to "Yes" bit... I'm not sure what I did wrong but if I try putting this after it then it won't work. I'm guessing I have an error (maybe a few) as to why I couldn't get it working.
And lastly, I'm wondering if there is a way whenever "No" radio buttons are selected that the fields can clear so that if "Yes" is selected, any previous entries do not appear. I couldn't figure out how to do this, I tried adding resets to those fields on the "No" buttons, but then that would clear the entry even if "Yes" is selected in one of the groups.
Any help here is greatly appreciated it. Thanks in advance.
