Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


javascript help

Explorer ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

Hi, I have two text fields groups (Text1-5 and t1-5).

I want if two field in both groups have same value to change fill color to green, I managed to make it work with loop but it only works if they are same number (Text2 and t2...etc) I want it to also work if they are diff number (example:Text3 and t5...etc).Here is my code:

for( var i=1; i<=5; i++){
if(this.getField("Text"+i).value != "" && this.getField("Text"+i).value === this.getField("t"+i).value){
this.getField("Text"+i).fillColor = color.green;
this.getField("t"+i).fillColor = color.green;}
else{
this.getField("Text"+i).fillColor = color.white;
this.getField("t"+i).fillColor = color.white;}}

TOPICS
JavaScript

Views

45

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

correct answers 1 Correct answer

Adobe Community Professional , Aug 06, 2021 Aug 06, 2021
Try this code: for (var i=1; i<=5; i++) { this.getField("Text"+i).fillColor = color.white; this.getField("t"+i).fillColor = color.white; } for (var i=1; i<=5; i++) { for (var j=1; j<=5; j++) { if (this.getField("Text"+i).value != "" && this.getField("Text"+i).value === this.getField("t"+j).value){ this.getField("Text"+i).fillColor = color.green; this.getField("t"+j).fillColor = color.green; } } }

Likes

Translate

Translate
Adobe Community Professional ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

For this you need two for loops.

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

I see, and where do I use second loop?

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

So you want to compare all the fields in the first group to all the fields in the second, and if the value of any pair is the same, turn those two fields green?

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Yes.

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Try this code:

 

for (var i=1; i<=5; i++) {
	this.getField("Text"+i).fillColor = color.white;
	this.getField("t"+i).fillColor = color.white;
}

for (var i=1; i<=5; i++) {
	for (var j=1; j<=5; j++) {
		if (this.getField("Text"+i).value != "" && this.getField("Text"+i).value === this.getField("t"+j).value){
			this.getField("Text"+i).fillColor = color.green;
			this.getField("t"+j).fillColor = color.green;
		}
	}
}

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

LATEST

Thanks, your awesome.

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