Skip to main content
Participant
December 21, 2023
Question

Getting Nan

  • December 21, 2023
  • 1 reply
  • 1155 views

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.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
December 21, 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
December 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.

Nesa Nurani
Community Expert
Community Expert
December 21, 2023

Scripts will not work on mobile devices.