Average of two form fields

New Here ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Hi I need some help with the below please

 

event.value = (this.getField("Keel to Truck").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value) / 2));

 

I would like find the average of two form fields "FWD DRAFT" and "AFT DRAFT" then subtract that value from another field called "Keel to Truck". The above is giving an answer, but not the correct one. Could someone please point me in the right direction.

 

Thanks. 

TOPICS
PDF forms

Views

348

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
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Apr 08, 2021 Apr 08, 2021
If  I correctly understand you should use : event.value = (this.getField("Keel to Truck").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value)) / 2); Instead of: event.value = (this.getField("Keel to Truck").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value) / 2));

Likes

Translate

Translate
Adobe Community Professional ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

What values does you get?

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
community guidelines
New Here ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

my test values are as follows

FWD DRAFT = 10.0

AFT DRAFT = 10.5

Keel to Truck = 60.0

 

The answer it is returning is 44.75. It should be returning a value of 49.75

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
community guidelines
Adobe Community Professional ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Looks like that it used the double value of FWD DRAFT.

 

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
community guidelines
New Here ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

it would appear so - wonder why its doing that.

 

so apart from that minor issue is the script correct??

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
community guidelines
Adobe Community Professional ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

"The answer it is returning is 44.75"

This answer is OK if your using:

event.value = (this.getField("Keel to Truck").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value) / 2));event.value = (this.getField("Keel to Truck").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value) / 2));

 

Otherwise your issue is in the JS calculation formula.

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
community guidelines
New Here ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

sorry I dont understand why the need for repeating the script. In simple terms the formula should be

60-((10+10.5)/2)=49.75 or

keel to truck - ((FWD DRAFT+AFT DRAFT)/2)

 

I actually think what is happening is that JS is dividing the AFT DRAFT by 2, not doubling the FWD DRAFT

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
community guidelines
New Here ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

I have solved the issue - just had one of the last parentheses in the wrong place.

 

Thanks for you help.

cheers. 

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
community guidelines
Adobe Community Professional ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Great minds think alike !

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
community guidelines
New Here ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Ha ha - its getting late down here in Australia!!!

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
community guidelines
Adobe Community Professional ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

If  I correctly understand you should use :

event.value = (this.getField("Keel to Truck").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value)) / 2);

 

Instead of:

event.value = (this.getField("Keel to Truck").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value) / 2));

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
community guidelines
Adobe Community Professional ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

You set it right, you just placed parentheses at wrong places, try like this:

event.value = this.getField("Keel to Truck").value - ((this.getField("FWD DRAFT").value + this.getField("AFT DRAFT").value) / 2);

 

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
community guidelines
New Here ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

LATEST

Yep - relised that. thank you though for taking the time to look at it. 

 

cheers. 

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
community guidelines