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

Community Beginner ,
Apr 03, 2020 Apr 03, 2020

Copied

Hi,

I have in PDF form ex. four number fields. A, B, C, D.
Field A is the entrance. Fields B and C do calculations (ex. A+B+C). Field D=A+B+C this is the result.
Now I want to make an auxiliary field D1.
Script operation. After entering the D1 value, the script substitutes the A value, checks the calculations and the D result, and works until the D = D1 condition is met
Thank you for any tips.

Edit
I came to this solution, but the result is always 1 too big

for (var i=1;this.getField("D1").value!=this.getField("D").value;i++){
this.getField("D").value=this.getField("A").value+this.getField("B").value+this.getField("C").value
this.getField("A").value=this.getField("A").value+1
};

TOPICS
Acrobat SDK and JavaScript

Views

300

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
8 Replies 8
Community Expert ,
Apr 03, 2020 Apr 03, 2020

Copied

Change the first line to :

while (this.getField("D1").value!=this.getField("D").value) {

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 Beginner ,
Apr 03, 2020 Apr 03, 2020

Copied

try67 Thank you, it works. I still have a problem with decimal numbers. At the moment I increase by 1 how to do it so that there are e.g. values of 3.56?

Edit:

I came to the solution (in bold) and it works for the result e.g. 3.50 but it does not work for the result e.g. 3.56 or 3.55

while (getField("D1").value!=this.getField("D").value){
this.getField("A").value=this.getField("A").value+=.1
this.getField("D").value=this.getField("A").value+this.getField("B").value+this.getField("C").value
};

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 Expert ,
Apr 03, 2020 Apr 03, 2020

Copied

Add 0.01 instead of 0.1... There must be a better way to solve this issue then by brute-force, though.

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 Beginner ,
Apr 03, 2020 Apr 03, 2020

Copied

Thank you for the answer, but it doesn't work.The form hangs.

Unfortunately, I have no other idea. I am not advanced in javascript

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 Expert ,
Apr 03, 2020 Apr 03, 2020

Copied

I'm not surprised. What you're doing is a classic recipe for getting an infinite loop.

What if the value is smaller, not bigger? The while-condition will never be false.

It's not a question of JS knowledge, but a question of math and logic. What exactly are you trying to achieve with this?

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 Beginner ,
Apr 03, 2020 Apr 03, 2020

Copied

I'm trying to do something that will work like a Goal Seek in Excel.

I know what you are writing but at the beginning I try to find a solution to the basic problem, e.g. only for rising values.

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 Expert ,
Apr 03, 2020 Apr 03, 2020

Copied

What you've shown above finds the value of A needed to satisfy D = D1.  What's the point? This value is simply

Given:

D = A + B + C

D1 = A1 + B + C

Difference:

D - D1 = A - A1

Result:

A1 = A - (D - D1)

Why the iteration?

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

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 Beginner ,
Apr 03, 2020 Apr 03, 2020

Copied

LATEST

Thank you Thom. However, my task is a bit more complicated. I tried to present them based on several variables, but it's probably not a good idea and I am misleading you. Thank you for your help and I am closing the topic on my part.