Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I make checkbox answers as dropdown list entries?

New Here ,
May 31, 2023 May 31, 2023

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:image.png

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!

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms
613
Translate
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
Community Expert ,
Jun 01, 2023 Jun 01, 2023

Check the JavaScript console for errors.

Translate
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
Community Expert ,
Jun 01, 2023 Jun 01, 2023

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

Translate
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
Community Expert ,
Jun 01, 2023 Jun 01, 2023
LATEST

 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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