Community Beginner ,
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, PDF forms

Views

103

Likes

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

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, PDF forms

Views

104

Likes

Report

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

Copied

Change the first line to :

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 03, 2020 1
Community Beginner ,
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
};

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 03, 2020 0
Most Valuable Participant ,
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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 03, 2020 0
Community Beginner ,
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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 03, 2020 0
Most Valuable Participant ,
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?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 03, 2020 0
Community Beginner ,
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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 03, 2020 0
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?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 03, 2020 1
Community Beginner ,
Apr 03, 2020