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

Calculation form field or Custom Entry

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

730

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

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

Votes

Translate

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

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

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

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

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

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

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

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

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