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

javascript help

Explorer ,
Aug 05, 2021 Aug 05, 2021

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
905
Translate
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
1 ACCEPTED SOLUTION
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;
		}
	}
}

View solution in original post

Translate
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 05, 2021 Aug 05, 2021

For this you need two for loops.

Translate
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

I see, and where do I use second loop?

Translate
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

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?

Translate
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

Yes.

Translate
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

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;
		}
	}
}
Translate
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
LATEST

Thanks, your awesome.

Translate
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