Skip to main content
Participant
November 16, 2017
Answered

How do I Show and Hide fields based on Yes or No radio buttons?

  • November 16, 2017
  • 2 replies
  • 2129 views

Trying to create a form, where if they check "Yes" or unchecking of "Yes" would also erase/hide the "A_Comments" box.

My issue is; if I uncheck "yes" the A_Comments field remains visible. Checking "No" does hide and blanks out any content.

I have the following code on the "Yes":

this.getField("A_Comments").display=display.visible;

and this on the "No":

this.getField("A_Comments").display=display.hidden

"A_Comments" field has the following text Field Properties:

Properties/General/Form Field: Hidden

Any help would be appreciated.

Regards,

This topic has been closed for replies.
Correct answer Thom Parker

Read this article:

https://acrobatusers.com/tutorials/show_hide_fields

It has exactly what you need

2 replies

rakeshk21205956
Inspiring
November 17, 2017

Use the following script :

In "yes" :  

if (event.value == "Yes"){

this.getField("A_Comments").display=display.visible;}

else

{this.getField("A_Comments").display = display.hidden;}

In "No": 

if (event.value == "No"){

this.getField("A_Comments").display=display.hidden;}

else

{this.getField("A_Comments").display = display.visible;}

DC-jr7138Author
Participant
November 17, 2017

Thanks, the behavior is not correct. Unchecking the "Yes" box did not hide the "A_Comments" field.

So, I used the following in the "YES" Box:

var nHide = event.target.isBoxChecked(0)?display.visible:display.hidden;

this.getField("A_Comments").display = nHide;

Clicking "yes" , on and off, would display and hide the "A_Comments" fields.

For "No", a plain checkbox works. As the above solved the display issue.

Thanks, rakeshk21205956

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
November 16, 2017

Read this article:

https://acrobatusers.com/tutorials/show_hide_fields

It has exactly what you need

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
DC-jr7138Author
Participant
November 17, 2017

Thanks for the link. A lot of reading, but was able to find the code needed for my issue.

Thom Parker
Community Expert
Community Expert
November 17, 2017

I knew you'd find it there! And now you know more about how Acrobat fields and scripts work. My work is done

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often