These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Set default value (defaultValue) of list box with multiple selections

landrew
Registered: Feb 15 2008
Posts: 12
Answered

Hello,

(This applies to Acrobat Javascript, version 5 or greater.)

I have a listbox with multiple selections. For example, I can set the current value to visible items 2 and 6 using:
f.currentValueIndices = [1,5];

I need to make the above values the default value. f.defaultValue = "abcd"; is great for a single item, but does not work for setting multiple items. For example f.defaultValue = [1,5]; is not valid.

The reference guide mentions export and user values but I cannot find any commands that will work.

In summary I need to set the default value of a list box with multiple items (indicies).

Thanks in advance.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Unfortunately there isn't a way to set default multiple selections from the Acrobat User Interface. Strangely enough, a default multiple selection is part of the PDF spec so it can be done (I've tested it and it works), Acrobat just isn't set up to do it. This is something you'll have to use a script for, and be a little creative.

For example, the list will maintain it's current selection when it is saved. So for the initail use you can just save the form with the default selections you want. If you have a reset button, then add a "Run a JavaScript" action to it, after the reset action", to setup your defaults.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

landrew
Registered: Feb 15 2008
Posts: 12
thomp,

We are thinking on the same wavelength as I had already tried that before I posted. Here is the button code:
// Reset Submit option fields
this.resetForm("Submit.Default");
var f = getField("Submit.Default.aPackets");
f.currentValueIndices = [1,5];

I am concerned about users selecting the clear menu option which will not be under my (javascript) control. What I can do is show an alert box after setting the listbox advising a save. I tried using a textbox to hold the array, setting the defaultValue on a listbox event.target, but the value is set on the 'next' change, so the textbox always has the previous value not the curent value. Ultimately, I am going to switch to multiple checkboxes as I can control the default values. I did not want to abandon the listbox until I had a definitive response fron the forum

Thanks for the answer (although not the one I wanted).