Skip to main content
Participant
May 21, 2020
Question

New to Adobe Forms

  • May 21, 2020
  • 3 replies
  • 601 views

I am working on creating a digital form that can be used for inpections at my workplace. I am using Adobe Acrobat Pro and Preparing the form from a pdf.

 

My question is this,

I have several text fields that are dependent on the choice of a dropdown at the top of the form. For example, if the user chooses "Bunker" from the "Substation" dropdown, only certain text fields will be applicable due to that selection. If the User chooses a differnt choice other fields will be applicable. They could be the same field or different fields based on the selection. I want to be able to tell the user what fields they will need to enter due to that selection.

How can I populate a field based on the selection. I want to be able to go into each field and write a script that will populate some value based on the dropdown selection. This is what I have tried.

 

if (this.getField("Substation")=="Bunker"){event.value = "N/A";}
else if (this.getField("Substation")=="Avery"){event.value = "Required"}
else if (this.getField("Substation")=="Fords P"){event.value = "N/A"}
else {event.value = "";}

ect.....

 

There are 27 possibilities for the dropdown field and 67 different fields that need to be populated.

 

This dosen't seem to be working. Any thoughts?

This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
May 23, 2020

You have to access the value of the fields, not just the fields themselves...

So change this:

if (this.getField("Substation")=="Bunker")

To:

if (this.getField("Substation").valueAsString=="Bunker")

And do the same in the other lines, too.

BarlaeDC
Community Expert
Community Expert
May 22, 2020

Hi,

I would also change your code to store the this.getField("Substation") in a variable as calling getField multiple times would delay processing, it would be better to use -

var substationField = this.getField("Substation");

then use this in your code

if ( substationField == ....

 

Regards

Malcolm

Thom Parker
Community Expert
Community Expert
May 22, 2020

I would suggest a different approach. Since all of this is being driven from the dropdown, use a script in the drop down.

Here's an article, and sample pdf that explains how to do this:

https://acrobatusers.com/tutorials/change_another_field/

 

You'll find lots more info about using dropdowns here:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
May 22, 2020

Thom

 

I did use a script in the dropdown however since I have so many fields that are dependent on the choice of the dropdown and there are so many choices in the dropdown, the script box will only alow me so many lines of code and I am exceeding it.

Bernd Alheit
Community Expert
Community Expert
May 22, 2020

For large scripts use an external editor.