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

Need help writing javascript

New Here ,
Oct 24, 2016 Oct 24, 2016

I need help writing javascript where I am dividing 2 fields and the answer is in a percentage.  I keep getting an error message and I know it is because I need to add javascript telling what to do when the answer is zero, but I am unsure how to do that.  This is what I currently have written in the Calculate tab under custom calculation script:

event.value = this.getField("Division 1 - 1").value / this.getField("Grand Total 1").value

and in the Format tab I have the category set to percentage.

The error I get is "The value does not match the format of the field"

Any help is much appreciated!  Thank you!!!

TOPICS
Acrobat SDK and JavaScript , Windows
412
Translate
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 ,
Oct 25, 2016 Oct 25, 2016

This issue was discussed here many times in the past... Basically this error happens when the divisor is zero, which is an illegal operation.

To prevent it you can do something like this:

var a = Number(this.getField("Division 1 - 1").value);

var b = Number(this.getField("Grand Total 1").value);

if (b==0) event.value = "";

else event.value = a/b;

Translate
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
New Here ,
Oct 25, 2016 Oct 25, 2016
LATEST

Thank you.  I have seen this question several times and tried to break down the answers to work for me, but I am not familiar with java script at all and was having a hard time.  I appreciate your help.

Translate
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