No calculation if one field is zero

New Here ,
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?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Add this as the custom validation script:

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

88

Likes

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

No calculation if one field is zero

New Here ,
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?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Add this as the custom validation script:

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

89

Likes

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
Aug 09, 2019 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Aug 09, 2019 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Aug 09, 2019 0
New Here ,
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.

Likes

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
Reply
Loading...
Aug 09, 2019 0
New Here ,
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.

Likes

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
Reply
Loading...
Aug 09, 2019 0
New Here ,
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?

Likes

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
Reply
Loading...
Aug 09, 2019 0
Most Valuable Participant ,
Aug 09, 2019

Copy link to clipboard

Copied

Add this as the custom validation script:

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

Likes

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
Reply
Loading...
Aug 09, 2019 1
New Here ,
Aug 12, 2019

Copy link to clipboard

Copied

Perfect, try67. I appreciate that.

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

Likes

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
Reply
Loading...
Aug 12, 2019 0