• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Nested If Statements

Community Beginner ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

434

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

correct answers 1 Correct answer

Community Expert , Jan 08, 2019 Jan 08, 2019

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

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

To:

event.value = Travel_Speed ;

Votes

Translate

Translate
Community Expert ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

To compare values use ==, not only =

Votes

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 ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

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

Votes

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 ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

just one more question, is there a limit to how many times you can nest if statements like that?

Votes

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 Expert ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

There is no limit.

Votes

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 ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

ok so i got everything in that text field to work and i moved that script over to another text field since it needs the same functionality, but it seems to be having a delay in the color change. say the range of values to turn the fill color green is 19 - 26, if i type in 19 the color wont change to green. but when i type in 20 it does change green and if i go back to 19 it stays green.  this text field is a little different since it pulls values from two different text fields and does a calculation before the if else statements. if this what is causing the delay?

var f = event.value; 
var wpds = this.getField("wpds1").value;
var dia = this.getField("dia1").value;
var pass = this.getField("pass1").value;
var Distance = this.getField("Distance").value ;
var Time = this.getField("Time").value ;
var Travel_Speed = Distance / Time * 60;

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

if (wpds == "UB36")
   {
    if (pass == "Root" || pass == "Hot")
               {
               if (dia == "3/32")             
                              {
                              if(f >= 18 && f < 29) {event.target.fillColor = ["RGB",0.800,1,0.800] ;} 
                              else  {event.target.fillColor = ["RGB",1,0.700,0.700]}    
                              }

                else if (dia == "1/8")             
                              {
                              if(f >= 19 && f < 31) {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 >= 21 && f < 32) {event.target.fillColor = ["RGB",0.800,1,0.800] ;}
                              else  {event.target.fillColor = ["RGB",1,0.700,0.700]}
                              }
                }

    else if (pass == "Fill" || pass == "Cap")
             {
             if (dia == "3/32")             
                              {
                              if(f >= 18 && f < 25) {event.target.fillColor = ["RGB",0.800,1,0.800] ;} 
                              else  {event.target.fillColor = ["RGB",1,0.700,0.700]}    
                              }

                else if (dia == "1/8")             
                              {
                              if(f >= 19 && f < 27) {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 >= 21 && f < 29) {event.target.fillColor = ["RGB",0.800,1,0.800] ;}
                              else  {event.target.fillColor = ["RGB",1,0.700,0.700]}
                              }

                else if (dia == "3/16")
                              {
                              if(f >= 22 && f < 31) {event.target.fillColor = ["RGB",0.800,1,0.800] ;}
                              else  {event.target.fillColor = ["RGB",1,0.700,0.700]}
                              }
                else if (dia == "7/32")
                              {
                              if(f >= 23 && f < 33) {event.target.fillColor = ["RGB",0.800,1,0.800] ;}
                              else  {event.target.fillColor = ["RGB",1,0.700,0.700]}
                              }
                }
    }

Votes

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 Expert ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

Where did you place this code?

Votes

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 ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

in the text field calculation field

Votes

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 Expert ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

But you said this field has a calculated value... Where is that calculation?

Votes

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 ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

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 ;

Votes

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 Expert ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

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

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

To:

event.value = Travel_Speed ;

Votes

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 ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

i did that but i still get the delay in color change, i still have to change the color mulitple times in the green range before the text box fill color changes to green. if i take the calculation out and just manually change the value the color changes as the proper value is shown. im not sure how else i can have that calculation and have the text box change color

Votes

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 Expert ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

Move the first line (where you define the f variable) after the line where you apply the new value to the field.

Votes

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 ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

LATEST

thanks for the help, that worked perfect

Votes

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
LEGEND ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

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

Votes

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