Expand my Community achievements bar.

SOLVED

Changing background color error

Avatar

Level 3

I am having trouble with a code I wrote for a form. It is working, however, it throws an error message and I don't understand why.

My field's default background fill color is set to white. Here is my code:

//Create a variable

var backgroundfilling;

//Subtract items to get the value of the field

this.rawValue = Num.rawValue - (Sub.rawValue);

if (this.rawValue < 0) {

    backgroundfilling = "231,179,173"; //Set the color to red if value is less than zero

}

else {

    backgroundfilling = "255,255,255"; //Set the color back to white if value is zero or greater

}

answer.fillColor = backgroundfilling; //Set the background color

Everytime I open or preview the form now, it gives an error that says: "Illegal value: cannot assign '255,255,255' to xfa[0].form[0].Page1[0].GeneralInput[0].answer[0].#value[0].#float[0]."

What??? Why is it throwing this error?

1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi,

Keep below script on the result text field on calculate event language Javascript.

//Subtract items to get the value of the field

var result = Num.rawValue - (Sub.rawValue);

if (result < 0) {

    this.border.fill.color.value = "231,179,173"; //Set the color to red if value is less than zero

}

else {

    this.border.fill.color.value = "255,255,255"; //Set the color back to white if value is zero or greater

}

this.rawValue = result;

Hope this works ..

Vjay

View solution in original post

6 Replies

Avatar

Employee

You need to use it this way: this.fillColor = ("255","255","255");

Modify your script in the foll. manner:

if (this.rawValue < 0) {

    this.fillColor= ("231","179","173"); //Set the color to red if value is less than zero

}

else {

    this.fillColor = ("255","255","255"); //Set the color back to white if value is zero or greater

}

Hope this is useful.

Avatar

Level 3

I made that change to my code. It isn't throwing the error anymore, but it's also not working at all now.

The field is now defaulted red, and it has a static value of 255 - it's not changing the value when I enter numbers into the other fields like it should.

Here is my code now:

//Subtract items to get the value of the field

this.rawValue = Num.rawValue - (Sub.rawValue);

if (this.rawValue < 0) {

    this.fillColor = ("231","179","173"); //Set the color to red if value is less than zero

}

else {

    this.fillColor = ("255","255","255"); //Set the color back to white if value is zero or greater

}

If I change it to this format: this.fillColor = ("231,179,173"); then the field starts working again, but it also throws the error again.

It's so weird. It's like the program doesn't know that fillColor is supposed to have three values?

Avatar

Employee

Is it that you want to use a color by getting the RGB values from some other fields?

Avatar

Correct answer by
Level 5

Hi,

Keep below script on the result text field on calculate event language Javascript.

//Subtract items to get the value of the field

var result = Num.rawValue - (Sub.rawValue);

if (result < 0) {

    this.border.fill.color.value = "231,179,173"; //Set the color to red if value is less than zero

}

else {

    this.border.fill.color.value = "255,255,255"; //Set the color back to white if value is zero or greater

}

this.rawValue = result;

Hope this works ..

Vjay

Avatar

Level 3

No.

You input values into two other fields. The third field subtracts those values. If the result is a positive number, it simply displays the number. If the result is negative, it displays the number AND shades the background of the field a red color.

Avatar

Level 3

That was perfect! Thanks so much!