Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
// 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;
Copy link to clipboard
Copied
// 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;
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now