Skip to main content
New Participant
January 15, 2022
Answered

PDF Form Multiple Drop downs with same selection Value to List Field data in Status Text field.

  • January 15, 2022
  • 3 replies
  • 2754 views

Hello

 

I am brand new to Javascript within functioning PDF forms and have been struggling for days to try and create the following function within my form.

 

I currently have 14 Dropdown boxes all with the same selections. The reason for this is to highlight the status of 14 asset’s within my company.

The selections are

Serviceable

Unserviceable

Away

Loaned

 

When a particular selection is made, I want a details in a text box to display, Asset Serial No and Remarks all filled in within different fields on the form. For example.

 

 

 

 

When Unserviceable is selected in the drop down box (Aircraft 2). In a text box called (Details AOG) I would like a statement created in the following format built up from ‘Tail’ – ‘Remarks’ to note there is also 14 fields for Tail an Remarks as the form is built for all 14 assets. If possible I would like this to appear or disappear depending if the A

ZZ331- Engine 2 Fail

 

 -

 

 

 

Text Box the Status is required.

 

 

 

I have been all over the Adobe community page and the help on here is fantastic. If anyone can direct me or offer me the Javascript they would use I would be really grateful.

This topic has been closed for replies.
Correct answer Nesa Nurani

See if this works for you:

var values = [];
for (var i=1; i<=14; i++) {
var v = this.getField("Aircraft"+i).valueAsString;
var t = this.getField("Tail"+i).valueAsString;
var r = this.getField("Remarks"+i).valueAsString;
if (v == "Unserviceable") values.push(v+" "+t+" "+r);}
event.value = values.join("\n");

3 replies

Thom Parker
Community Expert
January 15, 2022

What you are asking about is somewhat complex.

You should start with basic form scripting here:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

Since the "details" are coming from multiple fields, use a custom calculation script in the details field to assemble the text.    

https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm

 

You stated that there are several dropdowns with the same options. Do all dropdowns operate in the same way. With the exact same fields?  or the same type of fields in a different sections or groups?  Names are extremely important for this type of scripting. With the correct names you can write one script that will work for all of the different dropdowns.

 

  

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
New Participant
January 16, 2022

Thom

 

Thanks for the reply, I will look at those links this evening. I have 14 dropdowns named "Aircraft1 to 14" they all have the same list items Serviceable, Unserviceable, Away and Loaned. They all operate the same way and indicate the same for all 14 assets.

 

I have the following Javascript in the custom calculation script. It Currently allows when I select an Asset Unserviceable to indicate unserviceable in the "DetailsAOG" but that is it.

 

var values = [];
for (var i=1; i<=14; i++) {
var f = this.getField("Aircraft"+i);
var v = f. valueAsString;

if (v!="Serviceable" && v!="Away" && v!="Loaned") values.push(v);
}

event.value = values.join("\n");

 

 

 

Ideally I would like when I select an Asset Unserviceable. The Asset Serial No and Remarks for the Asset is indicated.  

 

Any thoughts or ideas would be really grateful.

 

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
January 17, 2022

See if this works for you:

var values = [];
for (var i=1; i<=14; i++) {
var v = this.getField("Aircraft"+i).valueAsString;
var t = this.getField("Tail"+i).valueAsString;
var r = this.getField("Remarks"+i).valueAsString;
if (v == "Unserviceable") values.push(v+" "+t+" "+r);}
event.value = values.join("\n");

John T Smith
Community Expert
January 15, 2022

When you post a question you always need to tell the program you are using
There are MANY programs in a full subscription, plus other non-subscription programs
Please post the exact name of the Adobe program you use so a Moderator may move this message to that forum

New Participant
January 15, 2022

Apologies

 

The program I created the PDF form on is:

 

Adobe Acrobat Pro DC (32-bit).

 

Again any help would be awesome, I am little stuck trying to get this to work.

 

New Participant
January 15, 2022

If possible I would like this to appear or disappear from the DetailsAOG Text field depending if the drop box has selected unserviceable or not.