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

Condition Logic for Check Box and Text Field with a Calculation

New Here ,
Feb 28, 2023 Feb 28, 2023

Copy link to clipboard

Copied

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!

TOPICS
Create PDFs , PDF forms

Views

2.4K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Mar 02, 2023 Mar 02, 2023

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;

Votes

Translate

Translate
Community Expert ,
Feb 28, 2023 Feb 28, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
New Here ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

Good catch, thanks Nesa, that comparison operator detail is a persistent human error. I fixed it in the post.  

However, that doesn't explain the syntax error, which is in the posters original code.  

 

Please post your entire calculation script. 

 

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

Votes

Translate

Translate

Report

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
New Here ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

Thank you, Nesa.

 

Would you mind please to post the entire script with your revision? Just to double check, I am using this as a calculation script not a mouse up action javascript, right?

Votes

Translate

Translate

Report

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 ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

The script above is now fixed by Thom, but if you still have an issue, please post your script, so I can take a look.

Votes

Translate

Translate

Report

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
New Here ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

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 ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

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
New Here ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

LATEST

Beautiful! Thank you both, Nesa and Thom!

Votes

Translate

Translate

Report

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