Question
Calculate average with color conditional formatting
I want to create a form where you enter values x1-x8 which return an average (avg), and if the average is <0,25 and >0,50 the field should turn red.

I have used the following script in "Custom calculation script":
var total = 0;
var avg = 0;
for(var i=1; i<=8; i++){
if(this.getField("x"+i).valueAsString != "" && Number(this.getField("x"+i).valueAsString) != 0){
total += Number(this.getField("x"+i).valueAsString);
avg++;}}
if(avg != 0)
event.value = total/avg;
else
event.value = "";
var v = Number(event.value);
if (v<0,25 && v>0,50) {event.target.fillColor = color.red;}
else if (v>=0,25 && v<=0,50) {event.target.fillColor = color.transparent;}The problem is that if the field turns red it stays red - it does not go back to transparent when the average value changes.
