Validate entry equals equation using another field

New Here ,
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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

269

Likes

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

Validate entry equals equation using another field

New Here ,
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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

270

Likes

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
Aug 23, 2017 0
Most Valuable Participant ,
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?

Likes

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
Reply
Loading...
Aug 23, 2017 0
New Here ,
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.

Likes

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
Reply
Loading...
Sep 28, 2017 0
Most Valuable Participant ,
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);

Likes

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
Reply
Loading...
Sep 28, 2017 0
New Here ,
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.

Likes

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
Reply
Loading...
Sep 28, 2017 0
try67 LATEST
Most Valuable Participant ,
Sep 28, 2017

Copy link to clipboard

Copied

Can you share the file?

Likes

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
Reply
Loading...
Sep 28, 2017 0