Skip to main content
New Participant
December 3, 2024
Answered

Validating calculation of total not individual components

  • December 3, 2024
  • 2 replies
  • 674 views

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.

This topic has been closed for replies.
Correct answer Nesa Nurani

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.

2 replies

try67
Community Expert
Community Expert
December 3, 2024

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

murray01Author
New Participant
December 3, 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.

try67
Community Expert
Community Expert
December 3, 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.

Bernd Alheit
Community Expert
Community Expert
December 3, 2024

What script do you use?

murray01Author
New Participant
December 3, 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.