Expand my Community achievements bar.

How to get JavaScript calculation to work on a form field

Avatar

Former Community Member
Hello,



I'm not new to JavaScript, but I am new to using it on fields in LiveCycle forms.



My form has the following fields:



Field1 contains current month's figure

Field2 contains past month's figure

Field3 needs to calculate to % of growth



So I attached the following javascript to the exit event of Field 2:



Field3.value = ((Field1 - Field2)*100)/Field2



But when I test the form by entering a value in Field1 and Field2, then tabbing out of Field2... absolutely nothing happens. No calculation, no error message, nothing.



I also tried Field3.value = ((Field1.value - Field2.value)*100)/Field2.value



Same result. What am I doing wrong?



Thanks in advance!

Kathryn
1 Reply

Avatar

Level 7
Have you looked at the Help files provided in LiveCycle Designer. The program can use JavaScript or FormCalc. Each of which has it own special syntax. This syntax is also different from the AcorForms JavaScript.



Since you are performing a division by a value that could have a value of zero, you will also have to provide for this situation.



Using FormCalc for the percent difference field's calculation:



if(Field2.rawValue ne 0) then

$.rawValue =( (Field1.rawValue - Field2.rawValue) / Field2.rawValue) * 100

} else {

$.rawValue = ""

}