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

Javascript: YES/NO radio button shows/hides multiple fields

Community Beginner ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

I know this should be simple, but I'm performing the same task on several forms and I need to make sure I'm using my time as efficiently as possible.  

I'm creating training checklists.  Each checklist has sections of Yes/No/NA radio buttons.  The trainer wants the trainee to read every section and make a choice for each item, even if the entire section doesn't apply.  Rather than require 10+ N/A clicks when an entire section isn't applicable, I'm making a YES/NO radio button at the top of each section.  It defaults to YES, leaving all the other radio fields in that section visible.  But when no is clicked, I want all the radio buttons in that section to be hidden.  

Since I will be using this same basic script several times with various object names, what's the basic Mouse Up script? 

Each "Section" radio set will be Section1, Section2, etc.

Taya5E88_0-1617396002345.png

Please help!  Thank you!

 

(Acrobat Pro DC)

 

TOPICS
JavaScript , PDF forms

Views

1.1K

Translate

Translate

Report

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 , Apr 05, 2021 Apr 05, 2021

this.getField("G1Q.1").display = (event.target.value=="YES") ? display.visible : display.hidden;

this.getField("G1Q.2").display = (event.target.value=="YES") ? display.visible : display.hidden;

Votes

Translate

Translate
Community Expert ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

The basic code to do it is this:

this.getField("OtherFieldName").display = (event.target.value=="YES") ? display.visible : display.hidden;

You can duplicate this line for each one of the fields you want to show/hide, adjusting the field name in the quotes each time.

Votes

Translate

Translate

Report

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 Beginner ,
Apr 04, 2021 Apr 04, 2021

Copy link to clipboard

Copied

I'm sorry, I'm so new to this and I'm trying so hard to "fake it til I make it"... But Javascript just doesn't make sense to me, no matter how much "beginners research" I do.  I've been troubleshooting and researching this for hours to make it work, but my brain can't wrap around it.

Would you please have mercy on me and be so kind as to break this down a little more for my old brain?

In my sample above the "Section Applicable?" YES/NO radio group is titled "Section1"
The Radio buttons below it that I want to show/hide are labeled "G1Q.1" then "G1Q.2" and so on.

 

What would my first Mouse up script look like for the radio group Section1 choice YES?

 

And what would it look like for choice NO?

 

Thank you so so so much!

Votes

Translate

Translate

Report

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 ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

this.getField("G1Q.1").display = (event.target.value=="YES") ? display.visible : display.hidden;

this.getField("G1Q.2").display = (event.target.value=="YES") ? display.visible : display.hidden;

Votes

Translate

Translate

Report

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 Beginner ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

I love you.  Thank you my friend!! (Even though I can't speak your Javascript language!)

Votes

Translate

Translate

Report

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 Beginner ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

What recommendations do you have for a newbie like me to learn the basics of Javascript?  I'm desperately seeking resources that will enable me to be self-sufficient and less dumbfounded.

Votes

Translate

Translate

Report

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 ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

LATEST

General JS tutorial (note that only the core syntax applies to Acrobat): http://www.w3schools.com/js/default.asp
Homepage for Acrobat JavaScript development, including a link to the full API: http://www.adobe.com/devnet/acrobat.html
Free tutorials about Acrobat in general, including many JS related ones: https://acrobatusers.com/tutorials/
A paid-for website with tutorials about Acrobat JavaScript (not related to me): http://www.pdfscripting.com/
My humble web-site with many tools for Acrobat and Reader (mostly paid-for, some free): http://www.try67.com

Votes

Translate

Translate

Report

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