• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to set the export values for dropdown list in Adobe PDF JavaScript?

New Here ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

I want to set the Export Values for a dropdown list in an Adobe pdf form using javascript. This is the code I have currently in the document-wide javascript:

var dropDownVal = ["one", "two", "three"];
var dropDownExportVal = [1, 2, 3];

var field = this.getField("Numbers");

field.setItems(dropDownVal);
field.exportValues(dropDownExportVal);

The dropdown list is populated with the dropDownVal array but the properties of the cell show no export value. Any assistance or links to documentation would be great.

TOPICS
How to , JavaScript , PDF forms

Views

2.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 06, 2022 Jan 06, 2022

You need to use a 2D-array as the parameter for setItems, like this:

 

var dropDownVal = [["one", 1], ["two", 2], ["three", 3]];
var field = this.getField("Numbers");
field.setItems(dropDownVal);

Votes

Translate

Translate
LEGEND ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

exportValues is a property, not a method. You assign to it, rather than call it. See the example in the API Reference. Also, the array should contain strings. Did you get an error in the JavaScript console? I'd expect one.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

Hey there, thanks for the reply. Here is the updated code based on your suggestions, is this correct? Unfortunately, the export values are still not showing:

var dropDownVal = ["one", "two", "three"];
var dropDownExportVal = ["1", "2", "3"];

var field = this.getField("Numbers");

field.setItems(dropDownVal);
field.exportValues = dropDownExportVal

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

You need to use a 2D-array as the parameter for setItems, like this:

 

var dropDownVal = [["one", 1], ["two", 2], ["three", 3]];
var field = this.getField("Numbers");
field.setItems(dropDownVal);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

This worked, thank you so much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Is it possible to use two separate arrays when using setItems? For example I have an array of 10 item numberss and another array of 10 values. Is there a way to use field.setItems() with the 2 arrays as the parameters? The first array for the item list and the second for the Export Value?If this is not possible, is there a way to use two separate arrays to create a 2 dimensional array? I have a list of over 100 items I need to add and typing each item and export value is not efficient.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

No. You have to use a single array with each item in it being another array, with 2 values in it.

Merging two arrays is easy, assuming they are the same length.

 

var arr1 = ["A", "B", "C"];

var arr2 = [1, 2, 3];

var arr3 = [];

for (var i=0; i<arr1.length; i++) arr3.push(arr1[i], arr2[i]);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Thank you for this information! It is not working as intended. This is what I am trying to accomplish. I have a part order form that I need to update. The form has multiple combo boxes with the same item lists and values. When we get an order for replacement parts, our employee will select the parts ordered, enter the quantity order and the form will automatically calculate the extended price based on the export value of the combo list item selected on the order line. We need to update this list, I would like to copy and paste the list items and export values and set the field using a javascript button. I found a snippet of code by georgez88320566 here which allows me to paste the list box items in a field, it then separates each line into an array using split and the carriage return character to create the array. I use this to create both arrays, but when I create the two dimensional array using the code you provided, it just combines both items into one. 

TlJI2336743141bg_0-1658351325128.png

 

Here is my function code:

 

(function () {

// Get the contents of the multi-line text field

// where the list values have presumably been pasted or otherwise entered

var sItems = getField("PartsList").valueAsString;
var sValues = getField("PartsPrice").valueAsString;

// Alert the user if the field is empty

if (!sItems||!sValues){

app.alert("Please enter a list of items in the text field below.", 3);

return;

}

// Create the array of items by splitting the string from the field

var aItems = sItems.split(/\r/);
var aValues = sValues.split(/\r/);
var aTwoDim = [];
for(var i=0; i<aItems.length;i++)aTwoDim.push(aItems[i],aValues[i]);

//

getField("Part").setItems(aTwoDim);

})();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 08, 2023 Feb 08, 2023

Copy link to clipboard

Copied

LATEST

@try67 , using your syntax, is it also possible to force the setItems command to include leading zeroes on the export values? I know how to do this in other situations using 'valueAsString', but I can't figure out how to make that work when setting the dropdown items dynamically.

var dropDownVal = [["one", 01], ["two", 02], ["three", 03]];
var field = this.getField("Numbers");
field.setItems(dropDownVal);

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines