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

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

598

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 , 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\".");

Votes

Translate

Translate
LEGEND ,
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.

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

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

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 ,
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\".");

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

Copy link to clipboard

Copied

LATEST

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.

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