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

Help with NaN

New Here ,
Oct 14, 2018 Oct 14, 2018

I'm new to calculations in PDFs and have built a series of calculations that should result in a 'Valid' or 'Invalid' message. The message is based on the final calculation being equal or higher than 31.38 (Valid) or lower than 31.38 (Invalid).

I keep getting a Not a Number (NaN) response in the final calculation and cannot see why. The code below shows my calculations, but please note that each calculation is in a separate Text Field in my PDF and is named Calc2, Calc3, etc.

The user of the PDF has to enter numbers in four fields; ResponseSampleA, ResponseSampleB, SizeSampleA and SizeSampleB.

Any help gratefully received.

// Text Field 1;

var a = this.getField("ResponseSampleA");

event.value = (a.value)/100;

// Text Field 2;

var b = this.getField("ResponseSampleB");

event.value = (b.value)/100;

// Text Field 3;

var c = this.getField("Calc1SampleA");

var d = this.getField("Calc1SampleB");

event.value = (d.value)/(c.value);

// Text Field 4;

var e = this.getField("Calc2");

event.value = (e.value)*100;

// Text Field 5;

var f = this.getField("Calc3");

event.value = (f.value)-100;

// Text Field 6;

var g = this.getField("ResponseSampleA").value;

var h = this.getField("ResponseSampleB").value;

if(h<g) {

event.value = (g/h)-1;

} else {

event.value = (h/g)-1;

}

// Text Field 7;

var i = this.getField("SizeSampleA").value;

var j = this.getField("SizeSampleB").value;

if(i<j) {

event.value = i;

} else {

event.value = j;

}

// Text Field 8;

var k = this.getField("Calc1SampleA");

event.value = 1-(k.value);

// Text Field 9;

var l = this.getField("Calc1SampleA");

var m = this.getField("Calc7");

event.value = (l.value)*(m.value);

// Text Field 10;

var n = this.getField("Calc8");

var o = this.getField("Calc1SampleA");

event.value = (n.value)*(o.value);

// Text Field 11;

var p = this.getField("Calc1SampleA");

var q = this.getField("Calc5");

event.value = (p.value)*(q.value);

// Text Field 12;

var r = this.getField("Calc10");

event.value = (r.value)*(r.value);

// Text Field 13;

var s = this.getField("Calc6");

var t = this.getField("Calc11");

event.value = (s.value)*(t.value);

// Text Field 14;

var u = this.getField("Calc8");

var v = this.getField("Calc12");

event.value = (v.value)/(u.value);

// Text Field 15;

var w = this.getField("Calc13").value;

if(w>=31.38) {

event.value = "Valid";

} else {

event.value = "Invalid";

}

TOPICS
PDF forms
6.6K
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
1 ACCEPTED SOLUTION
LEGEND ,
Oct 14, 2018 Oct 14, 2018
LATEST

The result of division by zero in Acrobat results in a value the if very large, very small, or non-existent. An empty field has a null value or zero value. Since you cannot divide by zero, you need to use conditional statements to prevent division by zero.

What happens when all of your fields have a non-zero or empty value?

Have you looked at the Acrobat JavaScript console for any other errors?

It appears you have several fields with names that you have not included in your description but have them in your calculations. The getField method does have a return value by which one can tell if the field has been found or not found.

I guess you want us to try to recreate your form with your assumed calculations that might cause the error. There could be other issues with your form, so the best approach is to provide a link to a copy of the form which could be examined.

The "NaN" result is indicating the result is Not A Number.

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
LEGEND ,
Oct 14, 2018 Oct 14, 2018
LATEST

The result of division by zero in Acrobat results in a value the if very large, very small, or non-existent. An empty field has a null value or zero value. Since you cannot divide by zero, you need to use conditional statements to prevent division by zero.

What happens when all of your fields have a non-zero or empty value?

Have you looked at the Acrobat JavaScript console for any other errors?

It appears you have several fields with names that you have not included in your description but have them in your calculations. The getField method does have a return value by which one can tell if the field has been found or not found.

I guess you want us to try to recreate your form with your assumed calculations that might cause the error. There could be other issues with your form, so the best approach is to provide a link to a copy of the form which could be examined.

The "NaN" result is indicating the result is Not A Number.

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