Skip to main content
Known Participant
January 7, 2019
Answered

Nested If Statements

  • January 7, 2019
  • 2 replies
  • 900 views

Hi

i am trying to create a form to that has a text field change color to either green or red depending on three things.  the first variable is a the text field "wpds1", the second is text field "dia1" and the third is the text field "Amps".  the user would input UB36 into the "wpds1" text field and either 5/32 or 1/8 into the "dia1" text field. When the user inputs a number into the "Amps" text field i want the color to change based on the input. here is what i got so far.

var f = event.value; 
var wpds = this.getField("wpds1").value;
var dia = this.getField("dia1").value;

if (wpds = "UB36")
   {

   if (dia = "1/8")             
                {
                if(f >= 70 && f < 131) {event.target.fillColor = ["RGB",0.800,1,0.800] ;} 
                else  {event.target.fillColor = ["RGB",1,0.700,0.700]}    
                }
   else if (dia = "5/32")
                {
                if(f >= 115 && f < 176) {event.target.fillColor = ["RGB",0.800,1,0.800] ;}
                else  {event.target.fillColor = ["RGB",1,0.700,0.700]}
                }
    }

The issue that i am having is when i enter 5/32 into the "dia" text field it is still running off of the numbers for 1/8. so when i put UB36 into "wpds1" and 5/32 into "dia" the range that changes the fill color to the desired color is still the 70 - 130.

This topic has been closed for replies.
Correct answer try67

I tried taking the calculation code and making it a global script but the same issue happened

var Distance = this.getField("Distance").value ;

var Time = this.getField("Time").value ;

var Travel_Speed = Distance / Time * 60;

this.getField("travelSpeed").value = Travel_Speed ;


Is this the calculation of "travelSpeed"? If so, change this line:

this.getField("travelSpeed").value = Travel_Speed ;

To:

event.value = Travel_Speed ;

2 replies

Inspiring
January 7, 2019

It is also possible to create a complex if statement using the logical  operands of AND (""), OR (||), and NOT ( ! ).

Bernd Alheit
Community Expert
Community Expert
January 7, 2019

To compare values use ==, not only =

Known Participant
January 7, 2019

thank you Bernd Alheit.... i have been trying to figure that out for hours