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

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

421

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

Community Expert , 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;
		}
	}
}

Votes

Translate

Translate
Community Expert ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

For this you need two for loops.

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

Copy link to clipboard

Copied

I see, and where do I use second loop?

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
Community Expert ,
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?

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

Copy link to clipboard

Copied

Yes.

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
Community Expert ,
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;
		}
	}
}

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

Copy link to clipboard

Copied

LATEST

Thanks, your awesome.

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