# need script to return blank field if input is zero

New Here ,
Mar 05, 2021 Mar 05, 2021

Copied

I'm using the following simplified notation to calculate a field:

100-[(Text3/Text1)*100]

If the input for Text3 and Text1 = 0, the result = NaN

I need a script that will return a blank field if the input is zero instead of NaN.

TOPICS
PDF forms

Views

44

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
4 Replies 4
Most Valuable Participant ,
Mar 05, 2021 Mar 05, 2021

Copied

Use this:

``````var v1 = Number(this.getField("Text3").valueAsString);
var v2 = Number(this.getField("Text1").valueAsString);
if (v2==0) event.value = "";
else event.value = 100-((v1/v2)*100);
``````

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Mar 05, 2021 Mar 05, 2021

Copied

Thank you that worked. Can you help with another question? I am calcuating the total number of filled in fields but do not want to include blank fields in the total. I am calculating the total using the following script:

var total = "";
for (var i=1; i<=7; i++) {
if (this.getField("Total"+i).value != "") total++; }
event.value = total;

How can I keep the blank fields from being included in the total? Thanks again for your help.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Mar 05, 2021 Mar 05, 2021

Copied

This code should do that, although you could change value to valueAsString in the third line.

Also, change the initial value of total to 0, instead of ""...

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Mar 05, 2021 Mar 05, 2021

Copied

LATEST

Perfect! Thank you.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources