Skip to main content
Inspiring
November 30, 2020
Question

Changing background color based on array

  • November 30, 2020
  • 2 replies
  • 549 views

Hello, what I'm trying to do is change the background color of text fields based on a number in an array that matches with the name of the text field in my pdf. The numbers are 0 to 100.  So if it is the number 0, it matches with one of the array elements then colors the background based on the first element. Here is the code I'm working on and I can't seem to get it to change the color, any advice on what I could do to make it work?

 

Thanks
Brian

 var colors = [
    ['blue', 99,98,95,94,91,90,89,80,29,20,19,18,13,12,11,10,9,8,5,4,3,2,1,0],
    ['green', 25,17,16,15,7,6],
    ['brown', 24,14],
    ['red', ],
];
  
for (var x = 0; x < 100; x ++)
{
	for (var i = 0; i < colors.length; i++){
		for (var j = 0; j< 100; j++){ 
			if (colors[i][j] = x){
				getField(getNthFieldName(x)).fillColor = color.colors[i][0];
			}
		}
	}
 
}
This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
November 30, 2020

The code is a bit of a mess, and contains errors. So the fields are named "0" to "100"?

Inspiring
November 30, 2020

Actually sorry, the fields are 0 to 99.  Sorry I'm trying to patch together a few examples I saw.  If i put in

getField(getNthFieldName(x)).fillColor = color.blue;

it works and turns all the fields blue.

 

Brian

Bernd Alheit
Community Expert
Community Expert
November 30, 2020

How many fields have you in the document?

Bernd Alheit
Community Expert
Community Expert
November 30, 2020

Check the Javascript console for errors.