Skip to main content
Participant
September 21, 2020
Question

Conditional Field Script

  • September 21, 2020
  • 2 replies
  • 3389 views

Hi,

 

I have a field on an Adobe Acrobat Pro DC form that I want to show or hide based on the value of another field.

 

My Conditional Field is Field A.

 

My Controlling Field is Field B.

 

I only want to show Field A when Field B = X. 

 

Otherwise, Field A is hidden.

 

Is there some script I can write in my form to accomplish this? 

 

If so, can someone help me out with the code for the script?  And tell me exactly where I should copy/paste this script into the form?

 

I appreciate the help.

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
September 21, 2020

George's script is exactly the right way to implement the show/hide functionality for a text field.

You can find more details (more complete info) on showing and hiding any kind of field here: 

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
September 21, 2020

The custom validation script for Field B could be:

 

// Custom Validation script for Field B

getField("Field A").display = event.value === "X" ? display.visible : display.hidden;

 

where "Field A" should be replaced with the exact field name of that field. Note that the script won't execute until the value of Field B changes, but once it does it will control the visiblity of Field A as expected. Enter the script on the Validate tab of the Field Properties dialog.

Participant
September 21, 2020

Hi,

Thank you for the response.  I copied the code as you indicated but it did not hide the field.  I uploaded photos of my Field A and Field B.  Including the validation script for Field A.

 

I only want Field A to show if Field B = 1.  But Field A shows for any value of Field B.

 

Can you do me a favor and look over my code and tell me whether I have it correct.

 

Thanks again for the help.

 

Below are screen shots of Field A General Tab, Field A Validation Tab, and Field B General Tab.

 

 

Nesa Nurani
Community Expert
Community Expert
September 21, 2020

Put the code in Field B.