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

Need help with NaN error and/or field do not match

New Here ,
Jan 06, 2022 Jan 06, 2022

I am trying to add two formulas to my pdf form:

Byanca5C3B_0-1641540579367.png

The first formula is for BMI which is 703*weight in pounds/height inches squared. I made the BMI box a number initially but an error came up that said fields don't match. I Imagine it is either because it is a long decimal or because there is a zero in the denominator until someone types a value in there. I changed the field to reflect "none" in formatting and now it is showing "NaN" until something is typed. I would like for "NaN" not to show.

 

I have ZERO knowledge of javascript, and just need to know what to type in and where. I figure the solution to the first formula will help me solve the second formula issue.

TOPICS
JavaScript
4.5K
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
5 ACCEPTED SOLUTIONS
Community Expert ,
Jan 07, 2022 Jan 07, 2022
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 ,
Jan 07, 2022 Jan 07, 2022

Format field as number with 2 decimals.

View solution in original post

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 ,
Feb 11, 2022 Feb 11, 2022

In your file you are missing parentheses at the end.

View solution in original post

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 ,
Mar 02, 2022 Mar 02, 2022

Since those fields have calculations they won't be blank so there is no point to check if field is "" and since you can't divide with 0 you need to check that divisor in this case field "Text14" is not 0 for calculation to trigger, like this:

if(this.getField("Text14").value == 0)
event.value = "";
else
event.value = Number(this.getField("Text13").value)/Number(this.getField("Text14").value);

View solution in original post

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 ,
Mar 05, 2022 Mar 05, 2022
LATEST

Instead of Simplified field notation use this as custom calculation script:

var c1 = Number(this.getField("Calc1").value);
var c2 = Number(this.getField("Calc2").value);
var c3 = Number(this.getField("Calc3").value);
var x = c1+c2+c3;
if(x == 0)event.value = "";
else
event.value = 18000/(2*x);

View solution in original post

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 ,
Jan 07, 2022 Jan 07, 2022

Post script you are using.

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 ,
Jan 07, 2022 Jan 07, 2022

This is the script: 703*pg8_2/(pg8_1*pg8_1). I've input this is the simplified field notation

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 ,
Jan 07, 2022 Jan 07, 2022
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 ,
Jan 07, 2022 Jan 07, 2022

Yes! this works. Is there a way to limit the answer to two decimal points?

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 ,
Jan 07, 2022 Jan 07, 2022

Format field as number with 2 decimals.

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 ,
Feb 11, 2022 Feb 11, 2022

Hi Nesa, Can you help me with two other formulas?

 

The first 

I have a formula in but my field is not calculating in my text 5 box. This is my formula:

 

(132.853-(0.0769*Text4))-(0.3877*Text6)+(Text3-(3.2649*Text1))-(0.1565*Text2)

 

I am not sure what I am doing wrong.

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 ,
Feb 11, 2022 Feb 11, 2022

In your file you are missing parentheses at the end.

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 ,
Mar 02, 2022 Mar 02, 2022

Hi Nessa,

 

Can you help me with this page as well? It seems my javascript is not working... I get an error when I open the file saying text 15 ..it says the value entered does not match the format of the field {text 15}. Ive attached the file.

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 ,
Mar 02, 2022 Mar 02, 2022

Checking if the fields are empty is not enough. You also need to make sure the second field's value is not zero. See the code I posted below.

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 ,
Mar 02, 2022 Mar 02, 2022

Since those fields have calculations they won't be blank so there is no point to check if field is "" and since you can't divide with 0 you need to check that divisor in this case field "Text14" is not 0 for calculation to trigger, like this:

if(this.getField("Text14").value == 0)
event.value = "";
else
event.value = Number(this.getField("Text13").value)/Number(this.getField("Text14").value);

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 ,
Mar 05, 2022 Mar 05, 2022

You've been so helpful! I just have one last file, it says my text field (pg36_1)does not match. Can you 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
Community Expert ,
Mar 05, 2022 Mar 05, 2022
LATEST

Instead of Simplified field notation use this as custom calculation script:

var c1 = Number(this.getField("Calc1").value);
var c2 = Number(this.getField("Calc2").value);
var c3 = Number(this.getField("Calc3").value);
var x = c1+c2+c3;
if(x == 0)event.value = "";
else
event.value = 18000/(2*x);

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 ,
Jan 07, 2022 Jan 07, 2022

NaN = Not a Number

This is a Format issue, can you share (part of) your document?


Acrobate du PDF, InDesigner et Photoshopographe
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 ,
Jan 07, 2022 Jan 07, 2022
 
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 ,
Jan 07, 2022 Jan 07, 2022

Use this code as the field's custom calculation script:

 

var v1 = Number(this.getField("pg8_1").valueAsString);
var v2 = Number(this.getField("pg8_2").valueAsString);
if (v1==0) event.value = "";
else event.value = (703*v2/(v1*v1));
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 ,
Jan 07, 2022 Jan 07, 2022

This typically happens when you divide a number by zero and try to apply the result to a Number field.

To avoid it you must use a script. If you post the exact formula you're using for that field's calculation we can help you convert it into such a script.

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 ,
Jan 07, 2022 Jan 07, 2022

This is the script: 703*pg8_2/(pg8_1*pg8_1)

I've input this is the simplified field notation

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 ,
Jan 07, 2022 Jan 07, 2022

As we assumed:

- input fields should have the "Number" format to avoid unwanted entries.

- the Simple Field Notation can't protect against division by zero or division by nothing, so you must use a JavaScript calculation.

 

Joker: calculated fields should be read only.

😉


Acrobate du PDF, InDesigner et Photoshopographe
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 ,
Jan 07, 2022 Jan 07, 2022

great. How do I add a tofixed(2) vaue to this script:

 

if(this.getField("pg8_4").valueAsString == "" || this.getField("pg8_5").valueAsString == "")
event.value = "";
else
event.value = Number(this.getField("pg8_4").value)/Number(this.getField("pg8_5").value);

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