• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Calculate on button click plus verify total

# Calculate on button click plus verify total

Community Beginner ,
Jan 20, 2023 Jan 20, 2023

Copied

I do not know any scripting and wonder if anyone can help:

I need a button to calculate the sum of 5 "numbers(percentage and sometimes the number will be 0)" then ensure they equal 100% - if not a warning - then if it matches the 100% the button will take the user to a page (this part I am sure is easy).

Thank you.

I know that you can run javascript from button and go to page view, it is the javascript portion I am unsure of.

TOPICS
How to , JavaScript , PDF forms

Views

516

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 Expert , Jan 22, 2023 Jan 22, 2023

Try this, if sum is not 100 you will get alert else if sum = 100 it will take you to page 2:

``````var a = Number(this.getField("PA").valueAsString);
var b = Number(this.getField("PB").valueAsString);
var c = Number(this.getField("PC").valueAsString);
var d = Number(this.getField("PD").valueAsString);
var e = Number(this.getField("PE").valueAsString);

var total = a+b+c+d+e;

if(total != 100)
else
this.pageNum = 1;``````

4 Replies 4
Community Expert ,
Jan 20, 2023 Jan 20, 2023

Copied

Actually, you can't use the "Go to a page view" action for this, as it can't be connected to the JS one. It all has to be done in a single script, but it's quite easily done. What are the names of the fields you want to add? Also, what do you mean by some are numbers and some are percentages? Is the total always the same? If not, you can't add those up.

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 Beginner ,
Jan 21, 2023 Jan 21, 2023

Copied

On click >>>

Calculate "sum" of PA + PB + PC + PD + PE (Not all will have an amount)

"sum"   If  = 100 continue

"sum"   If  = greater or less than 100 then "error message" = Total must equal 100

Trust this explains it clearly - thank you for the help.

I  assume that if I then add an action after running javascript to "Go to page" it will work or if needed in Javascript will be go to page 2.

Thanks.

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 Expert ,
Jan 22, 2023 Jan 22, 2023

Copied

Try this, if sum is not 100 you will get alert else if sum = 100 it will take you to page 2:

``````var a = Number(this.getField("PA").valueAsString);
var b = Number(this.getField("PB").valueAsString);
var c = Number(this.getField("PC").valueAsString);
var d = Number(this.getField("PD").valueAsString);
var e = Number(this.getField("PE").valueAsString);

var total = a+b+c+d+e;

if(total != 100)
else
this.pageNum = 1;``````

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 Beginner ,
Jan 22, 2023 Jan 22, 2023

Copied

LATEST

Thank you Nesa, appreciate the help. Works exactly as needed.

Have a lovely day.