Skip to main content
ls_rbls
Community Expert
Community Expert
Nov 14, 2025 8:47 PM UTC
Answered

Dropdown Menu Complicated Task with setItems()

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.

Thom Parker
Thom ParkerCorrect answer
Community Expert
Nov 14, 2025 11:25 PM UTC

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

3 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Nov 14, 2025 11:25 PM UTC

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)
}

 

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
ls_rbls
Community Expert
ls_rblsCommunity ExpertAuthor
Community Expert
Nov 15, 2025 2:43 PM UTC

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.

Translate
Technical Generalist
Thom Parker
Community Expert
Community Expert
Nov 17, 2025 6:50 PM UTC

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

 

Cheers, 

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