Skip to main content
ls_rbls
Community Expert
Community Expert
November 14, 2025
Answered

Dropdown Menu Complicated Task with setItems()

  • November 14, 2025
  • 1 reply
  • 160 views

Currently using this script in a combo box:

var ITEMS = [[" ", ""], ["ABC"], ["DEF"], ["HIJ"], ["KLM"]];


var DETAILS = [[" ", ""], [123], ["456"], ["789"], ["101112"], ["GO BACK..."];


{

if(event.value == "GO BACK..."){ event.target.setItems(ITEMS)}

if(event.value == "ITEMS") { event.target.setItems(DETAILS);}

}

This works great for what I need.

 

However, is it possible to also combine the script that @Thom Parker developed :"Using a Combo Box to Pre-populate Form Fields"??

 

For example

// Place all prepopulation data into a single data structure
var DeptData = { "123":{ contact: "Steala Damuni",
                              email: "accounting@mycomp.com",
                              deptnum: "cmp1234" },
                 "456":{ contact: "Frank N. Stien",
                              email: "engineering@mycomp.com",
                              deptnum: "eng1234" },
                 "789" :{ contact: "Shelly Oughtbuks",
                              email: "marketing@mycomp.com",
                              deptnum: "mkt1234" },
                 "101112":{ contact: "Goah  Wei",
                              email: "it@mycomp.com",
                              deptnum: "its1234" }};

function SetFieldValues(cDeptName)
{
  this.getField("DeptContact").value = DeptData[cDeptName].contact;
  this.getField("DeptEmail").value = DeptData[cDeptName].email;
  this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;
}

I woud like to, somehow, have this second script fill out various text fields once the user selects the second option:

if(event.value == "ITEMS") { event.target.setItems(DETAILS);} from that same dropdown menu.
 

It seems like is not possible.

 

But I am wondering if upon the combobox populating items when the user selectes this: if(event.value == "ITEMS") { event.target.setItems(DETAILS);}
if that that script can somehow be combined to achieve filling out other texfields employing a single data structure approach.

 

Is this possible at all?

 

Could it be this part [" ", ""] ?

 

I can't figure out how to make these two scripts work together.

 

 

Thanks for any help with this.

Correct answer Thom Parker

Yes of course.  Adjust the "if" statement to call setItems when the selection isn't blank or one of the change items. 

Like this. 

 

var ITEMS = [[" ", ""], ["ABC"], ["DEF"], ["HIJ"], ["KLM"], "ITEMS"];


var DETAILS = [[" ", ""], [123], ["456"], ["789"], ["101112"], ["GO BACK..."]];


if(event.value == "GO BACK..."){ event.target.setItems(ITEMS);}
else if(event.value == "ITEMS") { event.target.setItems(DETAILS);}
else if(event.value != ""){
   SetFieldValues(event.value)
}

 

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
November 14, 2025

Yes of course.  Adjust the "if" statement to call setItems when the selection isn't blank or one of the change items. 

Like this. 

 

var ITEMS = [[" ", ""], ["ABC"], ["DEF"], ["HIJ"], ["KLM"], "ITEMS"];


var DETAILS = [[" ", ""], [123], ["456"], ["789"], ["101112"], ["GO BACK..."]];


if(event.value == "GO BACK..."){ event.target.setItems(ITEMS);}
else if(event.value == "ITEMS") { event.target.setItems(DETAILS);}
else if(event.value != ""){
   SetFieldValues(event.value)
}

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
ls_rbls
Community Expert
ls_rblsCommunity ExpertAuthor
Community Expert
November 15, 2025

Amazing... simple ...and maximum clarity!   As always... 

 

Heck yeah!  the Jedi Master 

 

Thank you @Thom Parker .

 

Since  I joined the forums back in 2019 it took me this long to finally understand how placing together all data in a single structure works.

Thom Parker
Community Expert
Community Expert
November 17, 2025

You are very welcome!  JavaScript is great at making it easy to organize, access, and manipulate data. 

 

Cheers, 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often