if statement with two fields

Engaged ,
Aug 09, 2020

Copy link to clipboard

Copied

I'm having trouble combining two fields into calculating:

var a = this.getField("field1").value;
var b = this.getField("field2").value;
if (a == "1" || a == "2" || a == "3" && b == "10"){
event.target.fillColor = ["RGB", 254/255, 244/255, 175/255];
}else event.target.fillColor = color.transparent;

I also tried like this: || a == "3")&&(b == "10")
it doesn't work

"a" can be 1,2 or 3 but "b" also must be 10.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Replace the first three lines with this:

 

var a = this.getField("field1").valueAsString;
var b = this.getField("field2").valueAsString;
if ((a == "1" || a == "2" || a == "3") && b == "10"){

TOPICS
Acrobat SDK and JavaScript

Views

49

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

if statement with two fields

Engaged ,
Aug 09, 2020

Copy link to clipboard

Copied

I'm having trouble combining two fields into calculating:

var a = this.getField("field1").value;
var b = this.getField("field2").value;
if (a == "1" || a == "2" || a == "3" && b == "10"){
event.target.fillColor = ["RGB", 254/255, 244/255, 175/255];
}else event.target.fillColor = color.transparent;

I also tried like this: || a == "3")&&(b == "10")
it doesn't work

"a" can be 1,2 or 3 but "b" also must be 10.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Replace the first three lines with this:

 

var a = this.getField("field1").valueAsString;
var b = this.getField("field2").valueAsString;
if ((a == "1" || a == "2" || a == "3") && b == "10"){

TOPICS
Acrobat SDK and JavaScript

Views

50

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
Aug 09, 2020 0
Most Valuable Participant ,
Aug 09, 2020

Copy link to clipboard

Copied

Replace the first three lines with this:

 

var a = this.getField("field1").valueAsString;
var b = this.getField("field2").valueAsString;
if ((a == "1" || a == "2" || a == "3") && b == "10"){

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
Reply
Loading...
Aug 09, 2020 1
Engaged ,
Aug 09, 2020

Copy link to clipboard

Copied

Thank you that is working as intended.

If I may ask another question because field1 and field2 is getting their values from bunch of other fields that code sometimes work sometimes don't. Can I do something to make it more stable like format field1 and 2 as number or something else?

EDIT: among other fields, field2 also calculate its value from field1.

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
Reply
Loading...
Aug 09, 2020 0
Most Valuable Participant ,
Aug 09, 2020

Copy link to clipboard

Copied

You need to set the Fields Calculation Order correctly for it to work properly.

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
Reply
Loading...
Aug 09, 2020 0
Asim123 LATEST
Engaged ,
Aug 09, 2020

Copy link to clipboard

Copied

Thanks.

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
Reply
Loading...
Aug 09, 2020 0