Skip to main content
Participant
July 22, 2023
Answered

Text depending on 3 checkboxes

  • July 22, 2023
  • 2 replies
  • 336 views

What i would like.....

 

Checkbox 1 is Apple, Checkbox 2 is Pear, Checkbox 3 is Grape

When one or more checkboxes are checked i like to seen the fruit in in a textfiled."fruit"

Expample:

Checkbox 1 and 3 are checked the textfield "fruit" is: "Apple, Grape"

If just checkbox 2 is checked is should be "Pear" 

Checkbox 1 en 2 "Apple, Pear" or all " Aplle, Pear, Grape"

 

Can anyone help me??

I searched a lot but its hard for me to understand what is the right thing for me

This topic has been closed for replies.
Correct answer Thom Parker

Use a custom calculation script in the target "textfiled". (I just used the name you provided)

There are many different ways this could be done. 

The code below is one of the more novice level scripts. But its not the best way. 

 

var aOut = [];
if(this.getField("CheckBox 1").value != "Off")
   aOut.push("Apple");
if(this.getField("CheckBox 2").value != "Off")
   aOut.push("Pear");
if(this.getField("CheckBox 3").value != "Off")
   aOut.push("Grape");

event.value = aOut.join(", ");

 

2 replies

Participant
July 22, 2023

Thnx Thom,

 

It did what it had to do.

How easy can it be 😉 

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
July 22, 2023

Use a custom calculation script in the target "textfiled". (I just used the name you provided)

There are many different ways this could be done. 

The code below is one of the more novice level scripts. But its not the best way. 

 

var aOut = [];
if(this.getField("CheckBox 1").value != "Off")
   aOut.push("Apple");
if(this.getField("CheckBox 2").value != "Off")
   aOut.push("Pear");
if(this.getField("CheckBox 3").value != "Off")
   aOut.push("Grape");

event.value = aOut.join(", ");

 

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