Skip to main content
Inspiring
Nov 30, 2020 3:34 AM UTC
Question

Changing background color based on array

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

try67
Community Expert
Community Expert
Nov 30, 2020 9:16 AM UTC

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

Translate
Inspiring
Nov 30, 2020 4:06 PM UTC

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

Translate
Bernd Alheit
Community Expert
Community Expert
Nov 30, 2020 4:47 PM UTC

How many fields have you in the document?

Translate
Bernd Alheit
Community Expert
Community Expert
Nov 30, 2020 6:28 AM UTC

Check the Javascript console for errors.

Translate