Skip to main content
Participating Frequently
Aug 23, 2017 4:46 PM UTC
Answered

Validate entry equals equation using another field

I want to verify that user's entry in a field ("Line41") equals "Line40 * .02" or is blank or zero.  Customer will get a discount of 2% if paid by a certain date, otherwise entry on Line 41 will be zero (blank is acceptable).  I don't want to use a straight calculation in "Line41" because not all customers will get the discount.

I'm using Adobe Acrobat DC.  I'm a novice to JavaScript with a little experience.  Your help is appreciated.

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Sep 28, 2017 8:03 PM UTC

Use this code as the custom validation script of Line41:

var line40 = Number(this.getField("Line40").value);

var v = Number(event.value);

if (v!=0 && v!=(line40*0.2)) app.alert("Insert your warning message here.",1);

5 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Sep 28, 2017 8:03 PM UTC

Use this code as the custom validation script of Line41:

var line40 = Number(this.getField("Line40").value);

var v = Number(event.value);

if (v!=0 && v!=(line40*0.2)) app.alert("Insert your warning message here.",1);

Translate
KBrownAuthor
Participating Frequently
Sep 28, 2017 9:04 PM UTC

I entered that code and tested it.  I'm getting the warning message the first time I enter data in Line 41, even if it is correct.  If I return to the field using back-Tab (Shift + Tab) and re-enter the data, I don't get the message again.  Am I doing something wrong?  If user enters the correct data, I do not want the app alert.  Perhaps I didn't state that clearly in my earlier message.

Translate
try67
Community Expert
Community Expert
Sep 28, 2017 9:29 PM UTC

Can you share the file?

Translate
try67
Community Expert
Community Expert
Aug 23, 2017 5:16 PM UTC

So what should happen if it's not those values? And what should happen if it is?

Translate
KBrownAuthor
Participating Frequently
Sep 28, 2017 7:53 PM UTC

If user's entry does not equal, a popup message requesting they check their calculation.  If is does equal, keep user's entry.

Translate