listbox items can not be selected, always reverts to first item in list

New Here ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

I need some help.  using the setItems command the items appear in the list box selection but when i click on one of the items it always reverts to the first item in the list.  Here is the script im using. also the items do not clear if I type a diffeent value other than the 4 in the example below into the "route" text box.  Eventually I will need to put about 30 routes in.  Thanks for you help!

 

var l = this.getField("route1");

var R = this.getField("route").value;

if (R == 655) {l.setItems(["KTYR KDFW" , "KDFW KTYR"])}

else if (R == 658) {l.setItems(["KPSN KTYR KDFW", "KDFW KPSN"])}

else if (R == 660) {l.setItems(["F05 KSPS KDFW", "DFW KSPS F05" , "F05 KDFW" , "KDFW F05"])}

else if (R == 666) {l.setItems(["KABI KDFW", "KDFW KABI"])}

else i.clearitems();

TOPICS
General troubleshooting, How to, JavaScript, PDF forms

Views

133

Likes

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

Most Valuable Participant , Mar 09, 2021 Mar 09, 2021
Each time you call setItems it reverts to the default item in the list (the first one)... You need to use this code in an event that isn't constantly firing (like the Calculate event does), or add to it a command that preserves the currently selected item (if possible) after setting the items list. But the former is much better.

Likes

Translate

Translate
Adobe Community Professional ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

Where does you use the script? Don't use the script as calculation.

Likes

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 ,
Mar 17, 2021 Mar 17, 2021

Copy link to clipboard

Copied

Thanks. Yes I had it as a calculation but I moved it to validation and it works correctly but seems to be giving some platforms fits crashing acrobat or slowing it down a lot. So I'm still working on it. 

Likes

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
Most Valuable Participant ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

Each time you call setItems it reverts to the default item in the list (the first one)... You need to use this code in an event that isn't constantly firing (like the Calculate event does), or add to it a command that preserves the currently selected item (if possible) after setting the items list. But the former is much better.

Likes

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 ,
Mar 17, 2021 Mar 17, 2021

Copy link to clipboard

Copied

LATEST

Ok thanks for that. I'm still figuring it out. 

Likes

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