Skip to main content
Henry.Ong
Inspiring
July 19, 2018
Answered

How can we check if input field B is greater than Input field A?

  • July 19, 2018
  • 1 reply
  • 740 views

I have created a table in PDF. Two of the columns is Field A and Field B. Both are defined as numeric.

In another column of the same table, is the result of Field B less Field A. Field B should always be greater than Field A

What I want is to make sure that the result is a positive number. A negative number is invalid.

Examples:

This is Correct

Field A = 503

Field B = 510

Result is 7 (positive number)

This is Wrong

Field A = 432

Field B = 400

Result is -32 (negative number)

Is there a way I can trap the negative results?

This topic has been closed for replies.
Correct answer try67

It's tricky. I would say that you should use the validation script of Field B to make sure it's not smaller than Field A, but what if the user first fills in Field B, and then Field A? It won't work in that case.

If you just want to report the error to the user, and not necessarily prevent it, then you can use a simple validation script on the total field.
Basically this would work:

if (Number(event.value)<0) app.alert("The value in Field B must be the same, or bigger than, the value in Field A.");

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 19, 2018

It's tricky. I would say that you should use the validation script of Field B to make sure it's not smaller than Field A, but what if the user first fills in Field B, and then Field A? It won't work in that case.

If you just want to report the error to the user, and not necessarily prevent it, then you can use a simple validation script on the total field.
Basically this would work:

if (Number(event.value)<0) app.alert("The value in Field B must be the same, or bigger than, the value in Field A.");

Henry.Ong
Henry.OngAuthor
Inspiring
July 19, 2018

Thanks! The solution works!