View Full Version : Trying to get my script to recognize field in PDF as integer, not text

11-21-2012, 02:34 PM
I'm at my wits end trying to get what I know is probably something very simple to someone with even a little experience. I've got to add some javascript code to a PDF that will basically take the numbers from a number of other fields, add them up and put them into a field that I designate. Below is the code that I'm using, but all it does is put all the numbers into the field like they were text.

For example, if the numbers in the fields that I wanted to add together were 1, 5, 10, 20, and 45.5, the result would be 15102045.5

How do I get the script to recognize that these are integers and not string values? I've renamed the variables and field names for simplicity - they're not really the same values. PLease and thank you for anyone who can provide me with a solution!!!

function CalcAmtFin()
var A = (this.getField("A").value);
var B = (this.getField("B").value);
var C = (this.getField("C").value);
var D = (this.getField("D").value);
var E = (this.getField("E").value);
var F = (this.getField("F").value);
this.getField("RESULT").value = (A + B + C + D + E + F);

Philip M
11-21-2012, 04:03 PM
Input data is a string value until/unless it is changed into a number. The plus symbol + concatenates strings, but adds numbers.

so ..

var A = Number(this.getField("A").value);

and so on.

But 45.5 is not an integer. I assume you mean a "number".

You have realised that it is not a good idea to use the same name for an HTML element and a Javascript variable.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

11-21-2012, 05:33 PM
That helped a lot. After your suggestion, I then got a NaN result in my result field, which led me to change the properties for all the fields from "numeric" to "text" and then it worked. Getting the NaN at least let me know that the correct data was being passed. Again, thanks for the assistance, saved me another headache for sure!