Calculating an editable sum in Acrobat Pro DC

Jul 08, 2018

Copy link to clipboard

Copied

Hi guys,

I currently have a fillable PDF with a field called 'Total Chargeable Amount'. This is calculated by the sum of 10 other fields, which are all named 'A_1' up to 'A_10'.

This works fine using the built in calculation function, but I want the amount to be editable once it has been populated. I believe I need Javascript to make that possible.

Can anyone tell me what I should put in the 'Custom calculation script' field to do this?

Thanks!

Tom

Adobe Community Professional
Correct answer by BarlaeDC | Adobe Community Professional

HI,

There is but it would be a lot of work, as you would have to try and work out when a value is to be calculated, and then if the total field is edited, stop the calculation, but what if something in one of the calculated fields is changed, do we then run the calculation again, and then the user would have to enter the discount again, and then we have to stop the calculation again, and so on and so on.

It would be tricky to get this right, a much easier option is the one mentioned by try67​ which is to have a field that would be included in the sum to introduce the discount, although there is no need to call it "discount' you woundn't even have to name it you could just have a blank empty field, which is a discount when it has a value of nothing when it doesn't.

Regards

Malcolm

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

274

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

Calculating an editable sum in Acrobat Pro DC

Jul 08, 2018

Copy link to clipboard

Copied

Hi guys,

I currently have a fillable PDF with a field called 'Total Chargeable Amount'. This is calculated by the sum of 10 other fields, which are all named 'A_1' up to 'A_10'.

This works fine using the built in calculation function, but I want the amount to be editable once it has been populated. I believe I need Javascript to make that possible.

Can anyone tell me what I should put in the 'Custom calculation script' field to do this?

Thanks!

Tom

Adobe Community Professional
Correct answer by BarlaeDC | Adobe Community Professional

HI,

There is but it would be a lot of work, as you would have to try and work out when a value is to be calculated, and then if the total field is edited, stop the calculation, but what if something in one of the calculated fields is changed, do we then run the calculation again, and then the user would have to enter the discount again, and then we have to stop the calculation again, and so on and so on.

It would be tricky to get this right, a much easier option is the one mentioned by try67​ which is to have a field that would be included in the sum to introduce the discount, although there is no need to call it "discount' you woundn't even have to name it you could just have a blank empty field, which is a discount when it has a value of nothing when it doesn't.

Regards

Malcolm

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

275

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
Jul 08, 2018 0
Adobe Community Professional ,
Jul 09, 2018

Copy link to clipboard

Copied

HI,

I am not sure what you are trying to achieve, the field can be editable that is not a problem, but if we run a 'custom calculation script', this will run every time a field is exited, included the total field. This would mean that the user would edit the field, and then click or tab to another field, the calculations would run and then whatever they typed in would be overwritten.

I am sure this is not what you want to happen.

Regards

Malcolm

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
Reply
Loading...
Jul 09, 2018 1
Jul 09, 2018

Copy link to clipboard

Copied

Hi Malcolm.

Essentially, the Total Chargeable Amount may be less than the amount that is automatically calculated if a discount has been applied.

The changes that are made at the moment are overwritten as soon as you click away from the Total field, as you described.

Is there a way to prevent this from happening?

Tom

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
Reply
Loading...
Jul 09, 2018 0
Most Valuable Participant ,
Jul 09, 2018

Copy link to clipboard

Copied

I would recommend you create a separate field for the discount amount, and then include its value in the calculation of the total.

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
Reply
Loading...
Jul 09, 2018 1
Jul 09, 2018

Copy link to clipboard

Copied

Thanks try67. This is the fall back. The issue is we don’t want to ‘promote‘ discounts, if that makes sense.

Is there no way through applying code to do this?

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
Reply
Loading...
Jul 09, 2018 0
Adobe Community Professional ,
Jul 09, 2018

Copy link to clipboard

Copied

HI,

There is but it would be a lot of work, as you would have to try and work out when a value is to be calculated, and then if the total field is edited, stop the calculation, but what if something in one of the calculated fields is changed, do we then run the calculation again, and then the user would have to enter the discount again, and then we have to stop the calculation again, and so on and so on.

It would be tricky to get this right, a much easier option is the one mentioned by try67​ which is to have a field that would be included in the sum to introduce the discount, although there is no need to call it "discount' you woundn't even have to name it you could just have a blank empty field, which is a discount when it has a value of nothing when it doesn't.

Regards

Malcolm

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
Reply
Loading...
Jul 09, 2018 2