Skip to main content
Participating Frequently
August 23, 2017
Answered

Validate entry equals equation using another field

  • August 23, 2017
  • 2 replies
  • 1383 views

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 has been closed for replies.
Correct answer try67

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

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 28, 2017

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

KBrownAuthor
Participating Frequently
September 28, 2017

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.

try67
Community Expert
Community Expert
September 28, 2017

Can you share the file?

try67
Community Expert
Community Expert
August 23, 2017

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

KBrownAuthor
Participating Frequently
September 28, 2017

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