Skip to main content
gamzes93533812
Known Participant
February 12, 2018
Answered

Dynamically populating drop-down lists

  • February 12, 2018
  • 1 reply
  • 8576 views

Hi,

I wonder if it is possible to dynamically populate a drop-down list.

Very basically, I have a drop-down field called "countries". There are some options like, France, Spain, England, etc. but not all the countries.

I would like a user to add an item to the list, but not to duplicate an already existing item in the list.

I have seen it is possible in LifeCycle Designer but I only have license for Adobe Acrobat Pro DC at the moment.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
February 12, 2018
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
gamzes93533812
Known Participant
February 13, 2018

Thank you Thom for providing me very valuable articles corresponding particular needs.

I am trying to implement it buy using your example however I am stuck in very fist steps.

I basically created three form field (drop-down list) in Acrobat. Names:

Row1.AssemblySelect

Row1.PartSelect

Row1.Price

then I went to document JavaScript and I copied and pasted your code basically (please see below).

At the end I went to preview my doc, but fields are not populated. Could you please kindly point at what I am missing? I tried like a number of times.

//////test out////////

var oAssemblyParts = {

    Chasis: [

        ["-","None"],

        ["Rear Bracket",205.95],

        ["Front Bracket",185.95],

        ["Long Support",44.95],

        ["Front Bearing",48.95]

    ],

    Clutch: [

        ["-","None"],

        ["Plate 1",15.95],

        ["Plate 2",22.95],

        ["Inside Shaft",44.95],

        ["Outside Shaft",32.95]

    ],

    Brake: [

        ["-","None"],

        ["Master Cylindar",139.95],

        ["Slave Cylindar",85.95],

        ["Pad",15.95],

        ["High Presure line",22.95]

    ],

    Coolant: [

        ["-","None"],

        ["Pump",35.95],

        ["Thermostat",19.95],

        ["Coolant Line",8.95],

        ["Reservoir",17.95]

    ]

};

function SetPartEntries() {

    if(event.willCommit) {

        // Get the new parts list from the Master List

        // Since the selection is being committed,

        // event.value contains the Assembly name

        var lst = oAssemblyParts[event.value];

        // Clear the Parts list if there are no parts for the selected assembly

        if( (lst != null) && (lst.length > 0) )

        this.getField("PartSelect").setItems(lst);

        else

        this.getField("PartSelect").clearItems();

        // We have a new parts lists and the first entry is

        // is a non-selection, so clear the price field.

        this.getField("Price").value = 0;

    }

}

SetPartEntries();

//////test out////////

Bernd Alheit
Community Expert
Community Expert
February 13, 2018

Use the full names of the fields in your code.