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

# Checkbox calculations

New Here ,
Apr 02, 2024 Apr 02, 2024

Copied

Hello,

I work for a hospital clinic where we reimburse patients for mileage. We have a form in a word doc that I convert it into a PDF, and all I need to do is:

- If patient drove himself, when they check "drove self" I need to take the amount of miles they wrote down and multiply it by 0.625 and then the total will go under the self-drive column.

- If a volunteer drove the patient, when they check "volunteer drove" I need to take the amount of miles they wrote down and multiply it by 0.625 and then the total will go under self-drive column.

One check box is named DroveSelf and the other one is named VolunteerDrove.

The field box under the miles driven is called "MilesDrove"

The field box under the self-drive mileage @ 0.625 is called "SelfDrive"

The field box under Volunteer mileage @ 0.625 is called "VolunteerMileage"

So if a patient stated they self-drove 100 miles. They will need to check the box under "DroveSelf", then that will need to be multiplied by "MilesDrove" at 0.625 and that sum will need to go into "SelfDrive"

Can someone help me with a quick script? Thank you much!

TOPICS
Acrobat SDK and JavaScript

Views

91

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 Expert ,
Apr 02, 2024 Apr 02, 2024

Copied

LATEST

The best method is to have calculation scripts in both the "SelfDrive" and  "VolunteerMileage" fields.

Here's the Calc script for the SelfDrive field, the other one is nearly the same. The only difference is the checkbox that is used in the "if"

``````if(this.getField("DroveSelf").value != "Off")
event.value = 0.625 * this.getField("MilesDrove").value;
else
event.value = 0;
``````

However, you do have an issue.  It seems that these checkboxes should be mutually exclusive.

You can read how to make the checkboxes mutually exclusive, and how to write "if" statements here:

https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm

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