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

Search result adobe form

Community Beginner ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

 

Hi,
please help me solve my javascript problem. I'm not a specialist and I can't handle it.

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

236

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

Copy link to clipboard

Copied

Change the first line to :

while (this.getField("D1").value!=this.getField("D").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
Community Beginner ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

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

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

Copy link to clipboard

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?

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

Copy link to clipboard

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.

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

Copy link to clipboard

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

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

Copy link to clipboard

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.

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