Skip to main content
Participant
October 2, 2018
Answered

help comparing two fields to validate they're the same

  • October 2, 2018
  • 3 replies
  • 998 views

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.

This topic has been closed for replies.
Correct answer try67

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

3 replies

Inspiring
October 2, 2018

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.

try67
Community Expert
Community Expert
October 2, 2018

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.

Participant
October 2, 2018

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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
October 2, 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\".");

Legend
October 2, 2018

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.