Skip to main content
Kris Hunt
Legend
December 20, 2016
Answered

Combobox populated with Javascript keeps resetting to first option

  • December 20, 2016
  • 1 reply
  • 1105 views

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] ]);

This topic has been closed for replies.
Correct answer try67

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?


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.

1 reply

try67
Community Expert
Community Expert
December 20, 2016

Where did you place this code?

Kris Hunt
Kris HuntAuthor
Legend
December 20, 2016

On the combobox item, as a custom calculation script.

try67
Community Expert
Community Expert
December 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.