Alpha Numeric Fields
Copy link to clipboard
Copied
I am using a javascript on one pdf to change a numeric value into an alpha.
I use this on another pdf and it works fine, but when I use here it doesn't calculate.
I attached a dumbed down version of what I am working on.
I appreciate any help trying to solve this issue.
var strNumber = String(this.getField("TaxNumeric").value)
var nNumber = Number(strNumber);
event.value = ConvertToWords(nNumber);
function ConvertToHundreds(num) {
aTens = ["Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];
aOnes = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen",
"Eighteen", "Nineteen"
];
var cNum, nNum;
var cWords = "";
num %= 1000;
if (num > 99) {
/* Hundreds. */
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aOnes[nNum] + " Hundred";
num %= 100;
if (num > 0)
cWords += " and "
}
if (num > 19) {
/* Tens. */
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aTens[nNum - 2];
num %= 10;
if (num > 0)
cWords += "-";
}
if (num > 0) {
/* Ones and teens. */
nNum = Math.floor(num);
cWords += aOnes[nNum];
}
return cWords;
}
function ConvertToWords(num) {
var aUnits = ["Thousand", "Million", "Billion", "Trillion", "Quadrillion"];
var cWords = (num >= 1 && num < 2) ? "Dollar and " : "Dollars and ";
var nLeft = Math.floor(num);
for (var i = 0; nLeft > 0; i++) {
if (nLeft % 1000 > 0) {
if (i != 0)
cWords = ConvertToHundreds(nLeft) + " " + aUnits[i - 1] + " " + cWords;
else
cWords = ConvertToHundreds(nLeft) + " " + cWords;
}
nLeft = Math.floor(nLeft / 1000);
}
num = Math.round(num * 100) % 100;
if (num > 0)
cWords += ConvertToHundreds(num) + " Cents";
else
cWords += "Zero Cents";
return cWords;
}
Copy link to clipboard
Copied
HI,
When you say it works in another PDF but not on this one, do you mean that you are trying to use the same file in two different computers with different operating systems, for example, or different versions of Acrobat?
OR,
The same file was modified and you are using a copy of the original file in which the code was modified?
Copy link to clipboard
Copied
The field calculation order in your file is incorrect. You have the TaxAlpha field calculating before the TaxNumeric field, so it constantly uses the previous value, instead of the current one.
Copy link to clipboard
Copied
try67, perfect!! Thank you so much.

