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

Average of two form fields

Explorer ,
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

861

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

Community Expert , 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));

Votes

Translate

Translate
Community Expert ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

What values does you get?

Votes

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
Explorer ,
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

Votes

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
Community Expert ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

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

 

Votes

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
Explorer ,
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??

Votes

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
Community Expert ,
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.

Votes

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
Explorer ,
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

Votes

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
Explorer ,
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. 

Votes

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
Community Expert ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Great minds think alike !

Votes

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
Explorer ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

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

Votes

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
Community Expert ,
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));

Votes

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
Community Expert ,
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);

 

Votes

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
Explorer ,
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. 

Votes

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