Copy link to clipboard
Copied
Hi folks, new user here.
Have a text field that I would like to be hidden until one of two radio buttons in a group has been selected. All help greatly appreciated.
Rick S/San Antonio, TX
You can do this in different ways. Here is one example. Use the following as the custom calculation script in your text field that should be hidden or shown:
var f1 = this.getField("Group1");
var shouldBeVisible = (f1.value != "Off");
event.target.display = shouldBeVisible ? display.visible : display.hidden;
This can be shortened a bit, but shorter code is not necessarily more readable. If you are having problems understanding what's going on here, please review the JavaScript core language syntax.
...Copy link to clipboard
Copied
You can do this in different ways. Here is one example. Use the following as the custom calculation script in your text field that should be hidden or shown:
var f1 = this.getField("Group1");
var shouldBeVisible = (f1.value != "Off");
event.target.display = shouldBeVisible ? display.visible : display.hidden;
This can be shortened a bit, but shorter code is not necessarily more readable. If you are having problems understanding what's going on here, please review the JavaScript core language syntax. What you need to know is that a radio button group that has no selection will report "Off" as it's value. So the field should be visible when the radio button group is not set to "Off". In that case, we set the event.target.display property (you can find what that means in the Acrobat JavaScript API documentation: Acrobat DC SDK Documentation: event.target ) to display.visible or to display.hidden in the other case (again, more information is in the API documentation).
Copy link to clipboard
Copied
Hi again,
First... thank you for such a quick response... what a refreshing change !
Second... I did not pose my question with sufficient clarity.. so allow me to elaborate:
I have two radio buttons in a group: Group Name is: "English_YN", and the buttons are named "English-Yes" and "English-No". What I'd like to be able to do is keep another field called "Alt Language" hidden unless the "English-No" radio button has been clicked.
So,
if the radio button named "English-Yes" is selected, then "Alt Language" remains hidden, and can not be populated.
if the radio button named "English-No" is selected, then "Alt Language" is revealed and can be populated with the appropriate response.
I have coded in other languages, but am a COMPLETE BEGINNER in anything resembling JavaScript... I can sort of understand code that already exists, but have no new code development skill as of yet. As mentioned earlier, all assistance greatly appreciated !!
Many thanks & till later,
Rick Stockstill
San Antonio, TX
Copy link to clipboard
Copied
I went down a different path with my script. You can accomplish your goals with a slight variation on what I posted yesterday. See here for a script that should work for you:
var f1 = this.getField("English_YN");
var shouldBeVisible = (f1.value == "English-No");
event.target.display = shouldBeVisible ? display.visible : display.hidden;
As you can see, the structure of the script is the same, the big difference is in the comparison operation. We now know what button needs to be active in order to activate the text field. This again should be used as the custom calculation script for the "Alt Language" field.
Copy link to clipboard
Copied
Hi again,
OUTSTANDING !! Works perfectly.
Till later,
Rick S.
Copy link to clipboard
Copied
Hi yet again,
Can you recommend a good training reference (book, video, etc) that has good examples of doing this sort of stuff ? Please advise when you get a moment.
Till later,
Rick S.
Copy link to clipboard
Copied
Rick, there is a good introduction into programming in JavaScript for Acrobat: Beginning JavaScript for Adobe Acrobat
Most books/tutorials/trainings about JavaScript assume that you are going to use it within a web browser environment. You can use such a resource, but you need to be aware of where the dividing line between the "core language" and the web browser specific extensions is - you have to stick to the core language, and then fill in the Acrobat specific parts based on the API documentation:
Acrobat DC SDK Documentation: Developing Acrobat Applications Using JavaScript
Acrobat DC SDK Documentation: JavaScript for Acrobat API Reference
Copy link to clipboard
Copied
Hi again,
Much appreciated!! 🙂
Till later,
Rick S.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now