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

Custom Calculation Script on PDF Form

New Here ,
Jun 23, 2022 Jun 23, 2022

I have a PDF form created and I'm struggling with a custom calculation scripts. Currently there are two fields that need to be entered on the Form. Job Time and Materials Cost. 

 

What I need is a script that will take (Job Time * 100) + [Materials Cost + (Materials Cost x 40%)] and spit out a "Price" which is a field already on the form. 

 

Is there anyone that can help me with this?

TOPICS
JavaScript , PDF forms
3.0K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 23, 2022 Jun 23, 2022

// Acquire Inputs
var A = Number(this.getField("jobtime").valueAsString) * 100;
var B = Number(this.getField("materialscost").valueAsString);
var C = Number(this.getField("materialscost").valueAsString) * 0.4;

// Perform Calculation
var nSum = A + B + C;

// Assign Result to Field
event.value = nSum;

View solution in original post

Translate
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 ,
Jun 23, 2022 Jun 23, 2022

// Acquire Inputs
var A = Number(this.getField("jobtime").valueAsString) * 100;
var B = Number(this.getField("materialscost").valueAsString);
var C = Number(this.getField("materialscost").valueAsString) * 0.4;

// Perform Calculation
var nSum = A + B + C;

// Assign Result to Field
event.value = nSum;

Translate
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 ,
Jun 23, 2022 Jun 23, 2022
LATEST

For general refernce, here's an article on how to write a calculation script:

https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm

 

You'll need it to put the code Jeffery kindly provided into context. 

 

 

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

Translate
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