help comparing two fields to validate they're the same

New Here ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

I need the user to enter a dollar amount in field A then reenter it in field B.  I want to compare fields A and B and throw and error if they don't match.   how do I do this?  i have ZERO java experience so dumb it down for me!! thanks.

TOPICS
Acrobat SDK and JavaScript

Views

343

Likes

translate

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

Most Valuable Participant , Oct 02, 2018 Oct 02, 2018
For "Borrower 1 Amount":if (event.value && event.value!=this.getField("Borrower 2 Amount Re-enter").valueAsString) app.alert("Error! This value must match that of \"Borrower 2 Amount Re-enter\".");For "Borrower 2 Amount Re-enter":if (event.value && event.value!=this.getField("Borrower 1 Amount").valueAsString) app.alert("Error! This value must match that of \"Borrower 1 Amount\".");

Likes

translate

Translate

Translate
Most Valuable Participant ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

An important point is that you do not use Java, you use JavaScript (one word, never shortened to Java). The reason to point this out is, if you go searching the web for advice on Java, you will get information that is useless to you. Must be JavaScript; it must be Acrobat JavaScript, which is a special type.

Likes

translate

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
Most Valuable Participant ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

You can use this code as the custom validation script of field B:

if (event.value && event.value!=this.getField("A").valueAsString) app.alert("Error! This value must match that of field A.");

You should also enter the same thing (adjust the field names, of course) under field A, in case they change it after having changed B.

Likes

translate

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 ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

ok - so if my fields are called the following, what would the custom validation script say, specifically?

  • "Borrower 1 Amount" (aka Field A)
  • "Borrower 2 Amount Re-enter" (aka Field B)

Thanks in advance.

Likes

translate

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
Most Valuable Participant ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

For "Borrower 1 Amount":

if (event.value && event.value!=this.getField("Borrower 2 Amount Re-enter").valueAsString) app.alert("Error! This value must match that of \"Borrower 2 Amount Re-enter\".");

For "Borrower 2 Amount Re-enter":

if (event.value && event.value!=this.getField("Borrower 1 Amount").valueAsString) app.alert("Error! This value must match that of \"Borrower 1 Amount\".");

Likes

translate

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
Adobe Community Professional ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

You might want to add an additional check to see if the other field value you're comparing event.value to isn't blank. I'd find it annoying and probably confusing to get that error message in such cases, at least for the first field.

Likes

translate

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