Copy link to clipboard
Copied
Hello,
I'm brand spanking new to JavaScript and Adobe form fields, so I'm sure this is a very basic question. I am making a form which has two radio buttons "Option 1" and "Other (Please Specify)". I want the form to make a text field appear (and become required if possible) if someone selects the "Other (please specify)" radio button, but I don't want it to show up as an option if they picked "Option 1".
What is the best way to do this?
Thanks for your help.
Copy link to clipboard
Copied
Let's say the "radio button choice" values of these two options are "1" (for "Option 1") and "2" (for "Other"), and that the name of the text field is "Other". In that case, use this code as the Mouse Up event of both radio-button widgets:
var otherField = this.getField("Other");
if (event.target.value=="2") {
otherField.display = display.visible;
otherField.required = true;
} else {
otherField.display = display.hidden;
otherField.required = false;
otherField.value = "";
}
The only problem with this approach is that if the user resets the form while option 2 is selected the code is not triggered and the text field remains visible (and required)... To solve that you would need to use the calculation script of a (hidden) text field to trigger the code.
Copy link to clipboard
Copied
Can you provide the calculation script of the hidden text field for this scenario? Also, how would the script(s) be enhanced so that if Option 2 "Other (please specify)" were selected and text were entered in the "Other" text field, but then the user changed their mind and selected Option 1, the result would be the text field would clear and be hidden again.
Copy link to clipboard
Copied
Let's say radio button field name is "Group1", as custom calculation script of "Other" text field use this:
var f = this.getField("Group1").valueAsString;
if(f == "Other (please specify)")
event.target.display = display.visible;
else{
event.target.display = display.hidden;
event.value = "";}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now