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

Combobox populated with Javascript keeps resetting to first option

Mentor ,
Dec 20, 2016 Dec 20, 2016

I'm new to Javascript in PDF forms. I'm trying to put a combobox (named "Additional Users") on a PDF form that populates with values from an array. According to this help page, it looks like you can use a 2D array to store the keys and values for the combobox.

What I've done will populate the combobox, but once you select an option and click away from it, the value resets to the first option, which in this case is 0. In fact, even the example code from the help page does the same thing when I try it out in my form. What am I doing wrong?

     var dropdown = this.getField("Additional Users");

     dropdown.setItems([ ["0", 0], ["5", 5], ["10", 10], ["15", 15] ]);

TOPICS
Acrobat SDK and JavaScript
959
Translate
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 , Dec 20, 2016 Dec 20, 2016

Yes, it is. I just didn't realize that this would be something dynamic, until now...

If the values are dependent on the selection in a radio-button group then you should put this code as the MouseUp event of those buttons.

Translate
Community Expert ,
Dec 20, 2016 Dec 20, 2016

Where did you place this code?

Translate
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
Mentor ,
Dec 20, 2016 Dec 20, 2016

On the combobox item, as a custom calculation script.

Translate
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 ,
Dec 20, 2016 Dec 20, 2016

That means it will execute each time the value of any field in the file, including that one, is changed.

You only need to run this code once. You can do it from the console window and that's it.

Translate
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
Mentor ,
Dec 20, 2016 Dec 20, 2016

The final code will actually be part of a switch statement, though. If the user selects a certain radio button, then this combo box will have one set of options, and if they select another radio button, it will have a different set of options, etc. There are four radio buttons. So the combo box cannot populate until the user makes a selection, and if they change their selection, it should repopulate.

Isn't the console window just for debugging?

Translate
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 ,
Dec 20, 2016 Dec 20, 2016

Yes, it is. I just didn't realize that this would be something dynamic, until now...

If the values are dependent on the selection in a radio-button group then you should put this code as the MouseUp event of those buttons.

Translate
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
Mentor ,
Dec 20, 2016 Dec 20, 2016
LATEST

Thank you very much!

Translate
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