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

Validate entry equals equation using another field

New Here ,
Aug 23, 2017 Aug 23, 2017

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

990

Translate

Translate

Report

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 , Sep 28, 2017 Sep 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);

Votes

Translate

Translate
Community Expert ,
Aug 23, 2017 Aug 23, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Sep 28, 2017 Sep 28, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Sep 28, 2017 Sep 28, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Sep 28, 2017 Sep 28, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Sep 28, 2017 Sep 28, 2017

Copy link to clipboard

Copied

LATEST

Can you share the file?

Votes

Translate

Translate

Report

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