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;}}
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;
}
}
}
Copy link to clipboard
Copied
For this you need two for loops.
Copy link to clipboard
Copied
I see, and where do I use second loop?
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?
Copy link to clipboard
Copied
Yes.
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;
}
}
}
Copy link to clipboard
Copied
Thanks, your awesome.