Expand my Community achievements bar.

formCalc and JS IF Statement Not Working

Avatar

Level 2
I could use some help on this if statement:



if (field1.rawValue == 0)

{

this.rawValue = 0

}

else if (field2.rawValue == 0)

{

this.rawValue = 0

}

else (field2/field1)*100;



I know that the solution is most likely simple, but I'm not sure how to get this to work. The result I want is if field 1 is 0 or field 2 is zero then this field should equal field 2 divided by field 1 and the result multiplied by 100. These fields are all located within the same subform. I have also tried the following formCalc with no success either:



if(field1>0)|or(field2>0)then(field3=0)else*((field2/field1)*100)endif



Any help would be greatly appreciated.
2 Replies

Avatar

Level 7
You are using the right syntax for the "if then else" statement for Acrobat Forms JavaScript not the syntax for Designer. Designer uses the "then" in conjunction with the "if" and the "elseif" with nested "if then else" statements.



if (field1.rawValue == 0) then

this.rawValue = 0

elseif (field2.rawValue == 0) then

this.rawValue = 0

else (field2/field1)*100;

endif

Avatar

Level 5
You could just use the following JS code...

if (field1.rawValue > 0 && field2.rawValue > 0) {

this.rawValue = (field2/field1)*100;

}

else {

this.rawValue = 0

}



or the following FormCalc Code...

if ((Floor(field1.rawValue)> 0) and (Floor(field2.rawValue)> 0)) then

field3.rawValue =(Floor(field2.rawValue)/Floor(field1.rawValue))*100

else

field3.rawValue = 0

endif



Good luck,

SekharN