Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

New User - needs script help

New Here ,
May 12, 2016 May 12, 2016

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

TOPICS
Acrobat SDK and JavaScript , Windows
491
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 12, 2016 May 12, 2016

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.

...
Translate
Community Expert ,
May 12, 2016 May 12, 2016

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 13, 2016 May 13, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2016 May 13, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 13, 2016 May 13, 2016

Hi again,

OUTSTANDING !!    Works perfectly.

Till later,

Rick S.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 13, 2016 May 13, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2016 May 13, 2016

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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 13, 2016 May 13, 2016
LATEST

Hi again,

Much appreciated!!    🙂

Till later,

Rick S.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines