Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Scripts will not work on mobile devices.
Copy link to clipboard
Copied
Thnaks for the heads up.
Copy link to clipboard
Copied
To be clear. JavaScript does run in the mobile PDF viewers I mentioned.
Copy link to clipboard
Copied
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"
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more