Changing background color based on array

Community Beginner ,
Nov 29, 2020 Nov 29, 2020

Copy link to clipboard

Copied

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];
			}
		}
	}
 
}
TOPICS
Acrobat SDK and JavaScript

Views

67

Likes

translate

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
Adobe Community Professional ,
Nov 29, 2020 Nov 29, 2020

Copy link to clipboard

Copied

Check the Javascript console for errors.

Likes

translate

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
Most Valuable Participant ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

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

Likes

translate

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 Beginner ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

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

Likes

translate

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
Adobe Community Professional ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

How many fields have you in the document?

Likes

translate

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
Most Valuable Participant ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

You should not be using getNthFieldName for this. Simply access the field directly, like this:

this.getField(x)

Likes

translate

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