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

Writing a Javascript for a percent entry on a form....

Participant ,
Dec 01, 2017 Dec 01, 2017

Copy link to clipboard

Copied

Hopefully, someone can help me.  I created a form in Acrobat.  I set up one of the lines to enter as a percentage.  The issue is when I enter (for example 50 thinking it would be 50% it shows as 5,000%.)  I realize i could enter .50 and have it show up correctly.  I am not familiar with Javascripting, but I believe a script can be written so what ever is entered will show up correctly.  If I enter a 5 then it would show 5% etc.  Does anyone know how to write this?

I would greatly appreciate your help!!

Sincerely,

Steve

TOPICS
General troubleshooting

Views

1.4K

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

correct answers 1 Correct answer

Community Expert , Dec 01, 2017 Dec 01, 2017

Do not use the built in Format, select Custom on the Format tab and enter this script into the custom formatting box.

if(!/^\s*$/.test(event.value) && !isNaN(event.value)) event.value += "%";

This takes care of adding the % symbol, Now enter this code into the Keystroke script to prevent the user from entering non-numbers.

AFNumber_Keystroke(2, 0, 0, 0, "", true);

After this the display will revert to showing you entered a number format, but is will work the way you want

Votes

Translate

Translate
Community Expert ,
Dec 01, 2017 Dec 01, 2017

Copy link to clipboard

Copied

That's how Percent fields work. Their value ranges from 0 (0%) to 1 (100%). If you want it to work differently you would need to write your own keystroke, validation and format scripts.

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
Community Expert ,
Dec 01, 2017 Dec 01, 2017

Copy link to clipboard

Copied

Do not use the built in Format, select Custom on the Format tab and enter this script into the custom formatting box.

if(!/^\s*$/.test(event.value) && !isNaN(event.value)) event.value += "%";

This takes care of adding the % symbol, Now enter this code into the Keystroke script to prevent the user from entering non-numbers.

AFNumber_Keystroke(2, 0, 0, 0, "", true);

After this the display will revert to showing you entered a number format, but is will work the way you want

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Participant ,
Dec 01, 2017 Dec 01, 2017

Copy link to clipboard

Copied

LATEST

Excellent!!  Thank you so much.

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