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

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

644

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

Copy link to clipboard

Copied

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

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

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

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

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