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

No calculation if one field is zero

New Here ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

My original equation is 20250/(Downflow+Inflow)

I want the calculated field to be blank if the inflow field stays 0.

This is the code I've been playing with, but I just can't get it to take.

event.value = (20250/(getField("DownflowCFM").value + getField("InflowCFM").value));

if(getField("InflowCFM").valueAsString === 0)) event.value = "";

Can someone help, please?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

468

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 , Aug 09, 2019 Aug 09, 2019

Add this as the custom validation script:

if (this.getField("InflowCFM").valueAsString == "0") event.value = "";

Votes

Translate

Translate
LEGEND ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

What results are you getting with your script?

Is that result correct?

In most computer languages the "if" statement has an optional "else" statement. JavaScript is not an exception.

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 ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

You need to move the if-statement before the other line, and add an else at the start of that line.

Also, your condition doesn't cover the situation when the sum of both fields is zero. In that case you'll be dividing by zero, which is not an allowed operation.

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
New Here ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

The downflow will always have a value greater than 0, so it would never divide by zero.

The result is still there instead of blank when the inflow is 0. I want the field to be blank (or hidden) if the inflow is 0.

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
New Here ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

Ok. So there's the real issue. The calculations are working fine. I just would like it to be hidden if the inflow is 0. Sorry for the confusion.

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
New Here ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

I got rid of all the garbage and entered the simple equation into the Simplified field notation:

20250/((DownflowCFM)+(InflowCFM))

Can I hide the result if the inflow is 0?

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 ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

Add this as the custom validation script:

if (this.getField("InflowCFM").valueAsString == "0") event.value = "";

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
New Here ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

LATEST

Perfect, try67. I appreciate that.

Also, Thank you to the others helping me come to the conclusion.

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