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.
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));
Copy link to clipboard
Copied
What values does you get?
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
Copy link to clipboard
Copied
Looks like that it used the double value of FWD DRAFT.
Copy link to clipboard
Copied
it would appear so - wonder why its doing that.
so apart from that minor issue is the script correct??
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.
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
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.
Copy link to clipboard
Copied
Great minds think alike !
Copy link to clipboard
Copied
Ha ha - its getting late down here in Australia!!!
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));
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);
Copy link to clipboard
Copied
Yep - relised that. thank you though for taking the time to look at it.
cheers.