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

New Here ,
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.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use this:

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

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

var Percentage = percent / 100;

event.value = Value_a * Percentage;

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

539

Likes

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

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

New Here ,
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.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use this:

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

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

var Percentage = percent / 100;

event.value = Value_a * Percentage;

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

540

Likes

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
May 11, 2018 0
New Here ,
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

Likes

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
Reply
Loading...
May 11, 2018 0
Adobe Community Professional ,
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;

Likes

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
Reply
Loading...
May 12, 2018 0
ryguyspy LATEST
New Here ,
May 12, 2018

Copy link to clipboard

Copied

Thank you so much. This worked perfectly.

Likes

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
Reply
Loading...
May 12, 2018 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
May 12, 2018 0