Highlighted

Making Document Custom Calculation Script

New Here ,
Nov 19, 2020

Copy link to clipboard

Copied

I have a fillable PDF that is working how I want, but I'm wondering if I can make a document javascript that makes it easier for me? 

 

The forumla looks like this,

(MHPF1)*((InstalledRow1*.6)+(GlazedRow1*.3)+(CaulkedRow1*.1)) = Completed Man Hours

 

Instead of writing this for every Completed Man Hours row, can I make a document javascript to complete this? 

 

 

I attached the PDF for some help. 

 

 

How would I make it do this for each row? 

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

19

Likes

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

Making Document Custom Calculation Script

New Here ,
Nov 19, 2020

Copy link to clipboard

Copied

I have a fillable PDF that is working how I want, but I'm wondering if I can make a document javascript that makes it easier for me? 

 

The forumla looks like this,

(MHPF1)*((InstalledRow1*.6)+(GlazedRow1*.3)+(CaulkedRow1*.1)) = Completed Man Hours

 

Instead of writing this for every Completed Man Hours row, can I make a document javascript to complete this? 

 

 

I attached the PDF for some help. 

 

 

How would I make it do this for each row? 

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

20

Likes

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
Nov 19, 2020 0
Adobe Community Professional ,
Nov 19, 2020

Copy link to clipboard

Copied

Your formula is backwards: We use the "thing" that needs to be calculated on the left side:

 

completedManHours = (MHPF1)*((InstalledRow1*.6)+(GlazedRow1*.3)+(CaulkedRow1*.1));

 

... this just in case you want to convert this to JavaScript.

 

There are two ways you can approach this: With a global calculation script that is triggered by one of your fields. I usually use a hidden and read-only field for that, so that it does not interfere with the normal form operations. You would use a loop that loops over all your rows. You would use a JavaScript "for loop" for this. The trick now is to add a variable part to your script:

 

 

for (var i = 0; i < numberOfRows; i++) {
	this.getField("calculatedManHours" + i).value =
		this.getField("MHPF" + i).value * (
			(this.getFeld("InstalledRow" + i).value * 0.6) +
			(this.getField("GlazedRow" + i).value * 0.3) +
			(this.getField("CaulkedRow" + i).value * 0.1)
		);
}

 

 

You would have to define the variable numberOfRows for this to run.

 

Another option is to call your calculation function from each field that needs to be calculated. This does require that you touch every one of these fields, but you can do this with a script as well: You can set scripts for fields using the field.setAction() method:

 

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJ...

 

 

 

 

Likes

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
Reply
Loading...
Nov 19, 2020 0