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

Auto amount in words from numerical field

New Here ,
Sep 16, 2016 Sep 16, 2016

Copy link to clipboard

Copied

Dear All,

I need your help and guidance, Actually i had created an form, Wherein i had created a numerical field 'Amount' where user is supposed to enter the amount and beside that their is a text field which i had named 'Amount in Words'.

Now, request your help and guidance that is it possible that once user enter the amount in figure in 'Amount' Field. 'Amount in words' field should auto provide us the amount in words based on the value inputted in 'Amount' Field.

I am at beaning level of learning adobe live cycle designer and i recently purchased it. I would be great help if you can help on solving this issue.

If above is possible, Please provide me the solution in detailed steps to follow along with the java script to be used.

Thanks in advance.

Regard's,

Rakesh.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

753

Translate

Translate

Report

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 ,
Sep 17, 2016 Sep 17, 2016

Copy link to clipboard

Copied

Converting a number to words is a core JS task, not really related to Acrobat/Reader. There are plenty of examples of that online.

Let's say you find one that suits you and it's in a function called numberToWords(n). You can use it as the custom calculation of your "Amount in words" field like this:

event.value = numberToWords(Number(this.getField("Amount").value));

Votes

Translate

Translate

Report

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
LEGEND ,
Sep 17, 2016 Sep 17, 2016

Copy link to clipboard

Copied

This is an ambitious project for a beginner. One important thing about forums: we are here to help you learn how to work with JavaScript, not to do you job for you. So please don't ask for us to write code for you. Also be sure to note that LiveCycle Designer forms and Acrobat forms need different JavaScript.

Votes

Translate

Translate

Report

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
New Here ,
Sep 18, 2016 Sep 18, 2016

Copy link to clipboard

Copied

Thanks a lot for your suggestion "TestScreenName" and agreed to your comment that its an ambitious project for the beginner.

One more thing which i would like to say is that - at start every one is beginner and when some one reach the level of expert his responsibility is to share knowledge to other and if he cant do that, then at least he should motivate others.

Other who what to know the answer please find below the solution :
FORM1.Main.Subform1.Amount_in_words = Replace(Replace(WordNum(FORM1.Main.Subform1.AMOUNT, 2),"Dollars ",""), "Dollar ","");

FORM1.Main.Subform1.Amount_in_words - is the path for require result field

FORM1.Main.Subform1.AMOUNT - is the path of numerical field.

added , 2 for decimal - if not added - result will not show the decimal.

and added replace function to replace the default dollar which gets auto capture with the formula.

You can also add below if you require the result in Uppercase

FORM1.Main.Subform1.Amount_in_words = Upper(FORM1.Main.Subform1.Amount_in_words)

Votes

Translate

Translate

Report

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
New Here ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

where do you put this? in custom calculate script?

Votes

Translate

Translate

Report

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
LEGEND ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

This is a rather old post you are trying to resurrect.

First the linked example is for a from created in LiveCycle Designer and cannot be copied into a form created with Adobe Acrobat.

Next you will need to add a function to convert the numeric value into a string value. There are many examples of this and Adobe in previous versions of the Acrobat distribution CD provide a working example.

Votes

Translate

Translate

Report

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
LEGEND ,
Sep 18, 2016 Sep 18, 2016

Copy link to clipboard

Copied

Look in LiveCycle's "Help => Scripting". This is a built-in function in LiveCycle.

Votes

Translate

Translate

Report

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
LEGEND ,
Sep 18, 2016 Sep 18, 2016

Copy link to clipboard

Copied

We love to motivate and help people learn. We hate statements like "please proved the JavaScript".

I am delighted to learn of WordNum which makes a tough project easy. I don't think it is Acroforms though.

Votes

Translate

Translate

Report

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
LEGEND ,
Sep 18, 2016 Sep 18, 2016

Copy link to clipboard

Copied

Sorry, "proved" -> "provide"

Votes

Translate

Translate

Report

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
Explorer ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

LATEST

Just happened to stumble upon this post... I realize it's pretty old, but thought this might be helpful to some!

I believe this script was provided somehow through Adobe at some point, but I can't find the original post where I found it. It will convert a numerical amount into words Create a new document script with the following code...

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" ];

function ConvertToHundreds(num)

{

   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;

}

Then add the below script to the field where you want the words to be displayed:

event.value = "";

var f = this.getField("NUMERICAL_FIELD_NAME_HERE");

if(f.valueAsString != "") {

event.value = ConvertToWords(f.value);

}

Hope this helps!

Votes

Translate

Translate

Report

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