Copy link to clipboard
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.
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)
app.alert("Total must equal 100");
else
this.pageNum = 1;
Copy link to clipboard
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.
Copy link to clipboard
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.
Copy link to clipboard
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)
app.alert("Total must equal 100");
else
this.pageNum = 1;
Copy link to clipboard
Copied
Thank you Nesa, appreciate the help. Works exactly as needed.
Have a lovely day.