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

Getting Nan

Community Beginner ,
Dec 20, 2023 Dec 20, 2023

I have added a simple script to multiple a given number by the value in Field1 as follows:

 

event.value = Number(this.getField("Field1").valueAsString)*59.95;

 

This returns a Nan when I enter the value in Field1.

I'm a bit of a javascript hack but I can't see anything wrong with the above script. Can anyone please help debug it.

TOPICS
General troubleshooting , JavaScript , PDF forms
1.3K
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 ,
Dec 20, 2023 Dec 20, 2023

The first thing to do is to find out what is being returned by 

this.getField("Field1").valueAsString

 

Add this code to the top of the calculation script. 

console.println("Value:" + this.getField("Field1").valueAsString);

 

Add a new value to Field1 and then open the console to see the result.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Dec 21, 2023 Dec 21, 2023

Thanks Thom
Console returns value: 10 (which is the value I tried)
...but this was on my late model Mac with latest software. I found that the form works fine on this platform, but on an older iPad Air it returns the Nan value. Unfortunately there's no console on the iPad version of PDF reader Pro I am 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
Community Expert ,
Dec 21, 2023 Dec 21, 2023

Scripts will not work on mobile devices.

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 Beginner ,
Dec 21, 2023 Dec 21, 2023

Thnaks for the heads up.

 

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 ,
Dec 21, 2023 Dec 21, 2023
LATEST

To be clear. JavaScript does run in the mobile PDF viewers I mentioned. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Dec 21, 2023 Dec 21, 2023

What do you mean by "PDF reader Pro"?  What is the specific app being used?  As Nesa says, most moblie and browser PDF readers do not run JavaScript. However, there are a few that run a small subset, including the Acrobat Mobile Reader and the Readdle PDF Expert. 

 

I would suggest that for a test you change the script to this:

 

event.value = this.getField("Field1").valueAsString;

 

This will get you a step closer to the issue. If the field displays the correct value, then you'll know it 's the conversion with "Number" that is the problem.  In that case, try going with the field "value" property instead of "valueAsString"

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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