Skip to main content
Known Participant
February 28, 2023
Answered

Condition Logic for Check Box and Text Field with a Calculation

  • February 28, 2023
  • 1 reply
  • 3366 views

I'm back, again with another stumper. I also get my questions answered and am grateful for the help.

 

I have a field ("Hours") with a simple sum calculation, however, I am hoping that I can find a way that if a check box (Check Box1) is ticked, then the "Hours" field will display 0. Likewise in reverse. If that same check box is unticked, then the "Hours" field will revert to the original calcualtion. Is there a way to do this?

 

Thank you!

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

Thank you. 

 

if(this.getField("Check Box2.0").value == "Off")
{// Checkbox is unchecked
=Estimated S3 Worker Labor HoursRow1 + Estimated NonS3 Worker Labor HoursRow1
}
else// Checkbox is checked.
event.value = 0;


If those are field names use this:

if(this.getField("Check Box2.0").value == "Off"){
event.value = Number(this.getField("Estimated S3 Worker Labor HoursRow1").valueAsString)+Number(this.getField("Estimated NonS3 Worker Labor HoursRow1").valueAsString);}
else
event.value = 0;

1 reply

Thom Parker
Community Expert
Community Expert
March 1, 2023

Yes,

  

if(this.getField("Check Box1").value == "Off")
{// Checkbox is unchecked
   .. Original calculation ...
}
else// Checkbox is checked. 
   event.value = 0;

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
March 1, 2023

Thank you for your reply. This is not working. I copied and pasted, insterted the original calucation where indicated. I am getting a Syntax Error: missing; before statement 4: and line 5.

Nesa Nurani
Community Expert
Community Expert
March 1, 2023

EDIT: from what I can see, you are missing one '=' sign here: if(this.getField("Check Box1").value == "Off")