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?
Solved! Go to Solution.
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
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.
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?
Views
Replies
Total Likes
Is it that you want to use a color by getting the RGB values from some other fields?
Views
Replies
Total Likes
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
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.
Views
Replies
Total Likes
That was perfect! Thanks so much!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies