Check if two fields have same value

Explorer ,
May 21, 2018 May 21, 2018

Copy link to clipboard

Copied

I am trying to write a script that verifies that fieldA and fieldB do not contain identical strings.  And alerting the user if they are the same.  I have the following script (located in the validation of fieldB, but when I enter the same text in both boxes, no alert appears.

if(this.getfield("fieldA".value) == event.value) {

  app.alert("Must be different than fieldA");

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

170

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
community guidelines
Adobe Community Professional ,
May 21, 2018 May 21, 2018

Copy link to clipboard

Copied

You have errors in your code. Check the JS Console.

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
community guidelines
Adobe Community Professional ,
May 21, 2018 May 21, 2018

Copy link to clipboard

Copied

When comparing field values like it seems you want, you should use the valueAsString field property, so the code could look like:

if (this.getField("fieldA").valueAsString == event.value) {

  app.alert("Must be different than fieldA");

}

Note that event.value will always be a string in this context.

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
community guidelines
LEGEND ,
May 21, 2018 May 21, 2018

Copy link to clipboard

Copied

JavaScript is case sensitive for everything.

What should happen if both fields are empty?

Your script should allow for the fields to have their values be changed to another value or even to no value.

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
community guidelines
Explorer ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

LATEST

Thank you all.  I found the errors in my script.  The check works with .value or .valueAsString.  I added a qualifier to not perform the check if fields left blank.

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
community guidelines