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

Validating calculation of total not individual components

New Here ,
Dec 02, 2024 Dec 02, 2024

Hello,

I'm creating a grant application form with the following items:

A = total cost of project

B = deduct total amount of funds already on hand

C = total grant amount being applied for

The calculation is A-B=C. 

 

The valadation is: $0=> C <= $100,000. 

 

If A = $150,000 and B = -$90,000, then C = $60,000.

Because the calculation is automatically updated as soon as A is entered (and B has not been entered), then  C = $150,000 which automatically triggers an error message.

 

What would be the script to allow A to be >= $100,000, but yet C still has to be <= $100,000 once A and B are entered.  I tried playing with an IF-THEN statement, but no luck.  I don't want users to enter B first as it seems counterintuituve to start with a negative number in this scenario.  Any suggestions?  Thanks.

TOPICS
Acrobat SDK and JavaScript
445
Translate
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 , Dec 03, 2024 Dec 03, 2024

Because the calculation is automatically updated as soon as A is entered
You can set in a script to calculate only when A and B fields are filled.

Translate
Community Expert ,
Dec 02, 2024 Dec 02, 2024

What script do you use?

Translate
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
New Here ,
Dec 03, 2024 Dec 03, 2024

I don't have a script at the moment, so that is why I'm looking for a solution.  I'm very new to writing scripts.

Translate
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 ,
Dec 03, 2024 Dec 03, 2024

What should be the value of C if only A (or only B) are filled in, then?

Translate
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
New Here ,
Dec 03, 2024 Dec 03, 2024

The value of C is the total when A - B is calculated.  I don't want the value of C to be calculated and then validated until both A and B are entered.  At the validation, C must be <= $100,000.  The values of A and/or B could be "0".  

Example: A = $150,000 and B = -$90,000.

If you do the math on a piece of paper and as soon as you are finished writing $150,000, your brain doesn't trigger an error message because A is >=$100,000.  Rather, your brain waits for B to be written as -$90,000 before doing the calculation of $150,000-$90.000 and determing the result is $60,000 which is <=$100,000; thus, no error message gets triggered.

 

then C = $60,000.

Because the calculation is automatically updated as soon as A is entered (and B has not been entered), then  C = $150,000 which automatically triggers an error message.

Translate
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 ,
Dec 03, 2024 Dec 03, 2024

You can't validate a calculated field. Validation means checking the value and either accepting or rejecting it. This needs to be done in the fields that contain values the user enters, not ones with a calculated value.

You can replace the "bad" result with zero, or nothing, or "ERROR", but you can't reject it.

Translate
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 ,
Dec 03, 2024 Dec 03, 2024

Because the calculation is automatically updated as soon as A is entered
You can set in a script to calculate only when A and B fields are filled.

Translate
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
New Here ,
Dec 04, 2024 Dec 04, 2024
LATEST

Thank you Try67 and Nesa.  I ended up writing a simple script to give an error message under the text box if the value of C is >$100,000.

Translate
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