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

How to use the, "set Items" function with a drop down box, and an Array?

Explorer ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Good evening, I am attempting to use the "Set Items" function to add hundreds of words into a drop down box, using a for loop, and an Array.

I can use the same method of a loop to use the Array however I want, except for when it comes to adding the Array's contents into a drop down box.

Here is my code:

/*Here we will import, and read from a specific text file,

  and then assign the text file into an array, seperated by '\n' */

this.importDataObject("MED & DIAGNOSIS & ICD-10.txt", "C:/Users/dell/Documents/MED & DIAGNOSIS & ICD-10.txt");

var oFile = this.getDataObjectContents("MED & DIAGNOSIS & ICD-10.txt");

var cFile = util.stringFromStream(oFile, "utf-8");

var fileArray = cFile.split('\n');

/* Here, we will loop through the array equal to its length,

   attempting to add every other value in the array into a drop down box. 

   This portion of the code does not work, however.

   "console.println(MedAnalysis);" works just fine in the loop, for instance. */

var Drop = this.getField("Drop Test");

var index, i;

for (i = 0; i < fileArray.length; i++) {

Cartographer = fileArray.split('\t');

MedAnalysis = Cartographer[0]

Drop.setItems([MedAnalysis]);

}

Any help would be wonderful, thank you!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

396

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 , Feb 12, 2019 Feb 12, 2019

You need to use the setItems command once, outside the loop, on an array of items that contains just those values you want to apply.

So change this part:

for (i = 0; i < fileArray.length; i++) {

    Cartographer = fileArray.split('\t');

    MedAnalysis = Cartographer[0]

    Drop.setItems([MedAnalysis]);

}

To:

var items = [];

for (i = 0; i < fileArray.length; i++) {

    Cartographer = fileArray.split('\t');

    MedAnalysis = Cartographer[0];

    items.push(MedAnalysis);

}

Drop.setItems(items);

Votes

Translate

Translate
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

LATEST

You need to use the setItems command once, outside the loop, on an array of items that contains just those values you want to apply.

So change this part:

for (i = 0; i < fileArray.length; i++) {

    Cartographer = fileArray.split('\t');

    MedAnalysis = Cartographer[0]

    Drop.setItems([MedAnalysis]);

}

To:

var items = [];

for (i = 0; i < fileArray.length; i++) {

    Cartographer = fileArray.split('\t');

    MedAnalysis = Cartographer[0];

    items.push(MedAnalysis);

}

Drop.setItems(items);

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