Skip to main content
MaksDad07
Inspiring
May 21, 2018
Question

Check if two fields have same value

  • May 21, 2018
  • 3 replies
  • 1168 views

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

}

This topic has been closed for replies.

3 replies

Inspiring
May 21, 2018

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.

MaksDad07
MaksDad07Author
Inspiring
May 23, 2018

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.

Inspiring
May 21, 2018

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.

try67
Community Expert
Community Expert
May 21, 2018

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