Calculation form field or Custom Entry

New Here ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Hi All,

 

I have the following JS doing a calculation for me 

 

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

 

but would also like the option of overriding the calculated value with a manully inputed number. Is there an easy way to this??

Thanks

LC

TOPICS
PDF forms

Views

250

Likes

translate

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

Most Valuable Participant , Apr 19, 2021 Apr 19, 2021
Small correction: Use "Off", not "OFF".

Likes

translate

Translate

Translate
Adobe Community Professional ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

There are several ways to override a calculation. How do you want this to work. Do you want the user to just type into the field?  The easiest method is to use a checkbox to enable/disable the calculation.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

translate

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 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Sorry about the delay in getting back to you. I like the idea of chackbox to enable / disable the calculation - is this easy to do??

Thanks

LC

Likes

translate

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 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Add this code to the bottom of the calculation script. 

 

event.rc = this.getField("Checkbox").value == "Off";
event.target.readonly = event.rc;

 

When the checkbox is checked the field will block the calulation and allow user entry. When unchecked the calculation will proceed and the field will block user entry.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

translate

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 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

Thanks for the above. This is what I have done

 

event.value = (this.getField("KEEL TO TRUCK").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value))/2) event.rc = this.getField("AIR CALC").value == "OFF"; event.target.readonly = event.rc;

 

but its now not doing the calculation - I did also try the following

 

event.value = (this.getField("KEEL TO TRUCK").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value))/2);

event.rc = this.getField("AIR CALC").value == "OFF";

event.target.readonly = event.rc;

 

but that didnt work for me either. 

Likes

translate

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 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

Now you need to do a bit of debug. First check the consol window to see if any errors are reported.  Also, use the console window to ensure that this code

 

this.getField("AIR CALC").value == "OFF"

 

returns true when the checkbox is unchecked and false when checked. 

 

It would also be helpful it you could post the form. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

translate

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
Most Valuable Participant ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

Small correction: Use "Off", not "OFF".

Likes

translate

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 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

Thank you. it appears to be working as needed. Much appreaciated. 

Likes

translate

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
Most Valuable Participant ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

What should happen if they change the value of one of the other fields after entering a custom value?

Likes

translate

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 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

It wont matter if they change the one of the other values - somtimes the real life scenario is not the same as the calculation for various reasons. so once a number is manully entered I am happy for it to stay that way. The form constantly gets duplicated and blank one filled in each time I use it. 

Likes

translate

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