Skip to main content
Participating Frequently
February 25, 2022
Answered

Check Box If Statement

  • February 25, 2022
  • 2 replies
  • 1691 views

I have a simple IF statement in pdf fillable form.  If a checkbox is checked, then "See Below" will display in another field.  Works great!  However, when I uncheck the box, the field still displays the message and doesn't go blank.  Even the Clear Form doesn't clear the field.  HELP!  Thanks.

This topic has been closed for replies.
Correct answer Nesa Nurani

Hi Thom,

I am new to scripting in Adobe.  I am trying to make a form, that has a list of items that has checkboxes next to them.  What I want to happen is when a checkbox is checked, some specific text will fill a text box below the list.  And as other items are checked, specific text for them are added to the text box.
Is this possible?
Thanks!


You can use something like this as custom calculation script of text field:

var cList = [
 "Text for checkbox1", 
 "Text for checkbox2", 
 "Text for checkbox3", 
 "Text for checkbox4",
 "Text for checkbox5" 
];
event.value = "";
for(var i=0; i<=4; i++){
 var f = this.getField("Check Box"+i).valueAsString;
 if(f !== "Off")
  event.value += cList[i]+"\n";}

This assumes checkboxes are named "Check Box0","Check Box1",...etc, you can add more checkboxes just change to correct number in loop.

2 replies

Thom Parker
Community Expert
Community Expert
February 25, 2022

Please provide the script that is used for this action, and be specific about where the script is triggered. For example, is the script in the MouseUp Action for the checkbox?

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Gail5E85Author
Participating Frequently
February 25, 2022

The script is in the Calculation of the Test Field.

Bernd Alheit
Community Expert
Community Expert
February 25, 2022

What script does you use?

Gail5E85Author
Participating Frequently
February 25, 2022

I am very new to using script, so hope I am not too far off!  CRO is a checkbox for a class running outside business houirs.

 

var TEST = this.getField("CRO").value;
if( CRO = 1) event.value = "See Below"
else event.value = ""

Thom Parker
Community Expert
Community Expert
February 25, 2022

So then, this must be a calculation script on the field that is displaying the "See Below" text?  It's extremly important that we know where the script is being run. 

There are a few problems with the script, it's not that close. 

1.  the comparison operator is "=="

2.  is the export value from the checkbox 1? This is also crtical information. 

3.  There is no variable named CRO, the vaiable containing the checkbox value is named TEST.

 

Here is a calculation script that will work regardless of the export from the checkbox.

 

var TEST = this.getField("CRO").value;
if( TEST != "Off") event.value = "See Below";
else event.value = "";

 

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