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

calculate a percentage in adobe reader java script (total newbie)

New Here ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

I need to have an adobe acrobat form calculate a percentage. I have a field named, value_a that I need to multiply by a user entered value. For example is value_a is 100 and the user enters 20 in the percent field, I would like the form to calculate that 20% of 100 is 20. I don't know java script but this seems like it would be easy but I can't figure it out.

TOPICS
Acrobat SDK and JavaScript

Views

5.0K

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 , May 12, 2018 May 12, 2018

Use this:

var Value_a = getField("Value_a").value;

var Percent = getField("percent").value;

var Percentage = percent / 100;

event.value = Value_a * Percentage;

Votes

Translate

Translate
New Here ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

var Value_a = getField("Value_a").value;

var Percent = getField("percent").value;

var Percentage = (percent / 100).value;

event.value = Value_a x Percentage;

This is what I am trying to do. The Percentage variable is not a field in my form. I am trying to get it to calcluate the percentage value because the user will enter 5 for 5% off. It give me this error: missing ; before statement 4: at line 5

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 ,
May 12, 2018 May 12, 2018

Copy link to clipboard

Copied

Use this:

var Value_a = getField("Value_a").value;

var Percent = getField("percent").value;

var Percentage = percent / 100;

event.value = Value_a * Percentage;

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 ,
May 12, 2018 May 12, 2018

Copy link to clipboard

Copied

Thank you so much. This worked perfectly.

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 ,
May 12, 2018 May 12, 2018

Copy link to clipboard

Copied

It is best to use the "Percentage" format and then enter the decimal value. This will allow other calculations to directly used the stored value in the field in additional calculations without any type of conversion. Note that the "Format" option only changes the visually displayed value of the field and not the contents or actual value of the field. If you want to allow users to enter a whole number for the percentage, then use JavaScript to pop-up an app.response dialog to enter the whole number value and then compute the decimal value to be entered into the field.

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 Beginner ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

LATEST

Please can you help me with something similar?

I need to set a calculation so that when a person enters a number into the '5PercentageUplift' box it will add this to the '5OwnStockSubTotal' and give me the total '5TotalsPercentageOwnStock'.

 

Do I set the '5PercentageUplift' box to number or percentage?

 

Many thanks

 

Screenshot 2021-03-11 at 11.44.05.png

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