Skip to main content
Participant
October 12, 2023
Answered

When a checkbox is ticked, have certain text appear

  • October 12, 2023
  • 1 reply
  • 655 views

Hey guys,

 

I have searched many posts but unfortunately still haven't found a solution. I am very much a beginner when it comes to writing code(s). Hope you guys can help me.

 

So we have a PDF file which is an agreement. What I want is that when a certain checkbox is ticked, certain text appear. So f.e. checkbox 1 is ticked which is 12 months agreement. I want the text on another page to become 12 months. Checkbox 2 is 24 months and checkbox 3 is 36 months. Depending on the checkbox they tick I want the text to become the 12, 24 or 36 months. There are more checkboxes in the PDF file (fyi).

A bonus would be if none of the checkboxes are ticked it would say 12 months, since the minimal duration of the contract will always be 12 months. But if that isn't possible then empty is fine too.

 

Thanks in advance!

This topic has been closed for replies.
Correct answer try67

You can do that using a (read-only) text field. Say the check-box group is called "Duration" with export values of "12", "24" and "36". Create the text field in the desired location (call it "Duration text", for example), set it as Read-Only and apply the following custom calculation script to it:

 

var duration = this.getField("Duration").valueAsString;
if (duration=="Off") event.value = "12";
else event.value = duration;

 

As for the default value of 12, the script above takes care of it (line #2), but I would strongly recommend to do it differently. You should go to the Properties of the "12" check-box and under Options tick the box next to "Check box is selected by default". That way that box will be selected when the form is cleared. However, the user would still be able to un-tick it manually, of course.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
October 12, 2023

You can do that using a (read-only) text field. Say the check-box group is called "Duration" with export values of "12", "24" and "36". Create the text field in the desired location (call it "Duration text", for example), set it as Read-Only and apply the following custom calculation script to it:

 

var duration = this.getField("Duration").valueAsString;
if (duration=="Off") event.value = "12";
else event.value = duration;

 

As for the default value of 12, the script above takes care of it (line #2), but I would strongly recommend to do it differently. You should go to the Properties of the "12" check-box and under Options tick the box next to "Check box is selected by default". That way that box will be selected when the form is cleared. However, the user would still be able to un-tick it manually, of course.

Participant
October 12, 2023

Thank you so much, this worked perfectly!