Skip to main content
Participant
June 1, 2023
Frage

How can I make checkbox answers as dropdown list entries?

  • June 1, 2023
  • 3 Antworten
  • 800 Ansichten

Hi all, 

I am trying to create a dropdown list with its selection generated from checkbox answers. For example if I tick 5 checkbox, the 5 answers from the checkbox will auto populate the dropdown list entries.  I have attached the picture below to give an example of what I meant:

I have tried using the script below to do this but it doesn't work.

 

// Get the dropdown field
var dropdown = this.getField("Root Cause");

// Get the checkbox field
var checkbox = this.getField("Low learning aptitude");

if (checkbox.value === "Yes") {
var isOptionExists = false;
for (var i = 0; i < dropdown.numItems; i++) {
if (dropdown.getItemAt(i).value === optionValue) {
isOptionExists = true;
break;
}
}


if (!isOptionExists) {
var count = dropdown.numItems
dropdown.insertItemAt("People - Low learning aptitude","People - Low learning aptitude");

}

}

 

If anyone can help it would be  much appreciated!

Dieses Thema wurde für Antworten geschlossen.

3 Antworten

Thom Parker
Community Expert
Community Expert
June 1, 2023

 Give all of the checkboxes with a group name, for example "RootCauseQ.Low learning aptitude"

Then place the text you want displayed in the list for a particular checkbox, into the tooltip for that checkbox. 

This code will collect the answers and fill the text box.

var aItemList = [];
var aCheckList = this.getField("RootCauseQ");
for(var i=0;i<aCheckList.length;i++)
{
    if(aCheckList[i].value == "Yes")
        aItemList.push(aCheckList[i].userName);
}
this.getField("Root Cause").setItems(aItemList);

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Nesa Nurani
Community Expert
Community Expert
June 1, 2023

Collect checked answers into array and then set items to dropdown.

Bernd Alheit
Community Expert
Community Expert
June 1, 2023

Check the JavaScript console for errors.