Copy link to clipboard
Copied
Hello,
I have a form where users are asked to enter 5 numbers as percentages, where they are all supposed to total 100%.
I need to have an error pop up if the total does not equal 100%. I have found scripts that can do this however, if the script is for under or equals 100, there is a pop up after every number is entered which isn't ideal.
Is there a way to do this validation that only provides an error if the total is under or over 100% but only once all the 5 fields have been filled? (i.e., once/if none of the fields are zero)
Please let me know! Thanks.
Copy link to clipboard
Copied
You didn't provide field names, so I use "Text1"-"Text6" ( make sure your fields are named in sequence)
as custom calculation script of total field use this:
var sum = 0;
var check = 0;
for(var i=1; i<=6; i++){
if(this.getField("Text"+i).valueAsString != ""){
check++;
sum += Number(this.getField("Text"+i).value);}}
if(check == 6 && sum != 100)
app.alert("enter message here");
event.value = sum;
Copy link to clipboard
Copied
Is a value of 0 allowed in the fields?
Copy link to clipboard
Copied
No - all fields must have a number over zero
Copy link to clipboard
Copied
Display the popup only when all values are greater as zero.
Copy link to clipboard
Copied
You said user enters 5 numbers, in your screenshot there are 6 percentage fields+total percentage fields?
What are names of the fields?
Copy link to clipboard
Copied
Apologies - they complete 6 lines which are totalled. I've attached a clearer screenshot
Copy link to clipboard
Copied
You didn't provide field names, so I use "Text1"-"Text6" ( make sure your fields are named in sequence)
as custom calculation script of total field use this:
var sum = 0;
var check = 0;
for(var i=1; i<=6; i++){
if(this.getField("Text"+i).valueAsString != ""){
check++;
sum += Number(this.getField("Text"+i).value);}}
if(check == 6 && sum != 100)
app.alert("enter message here");
event.value = sum;
Copy link to clipboard
Copied
Sorry about that - my field names are A19.1, A19.2, A19.3, A19.4, A19.5 and A19.6.
So would I inser each of those in to the "Text" field? Thanks - i'm new to this so this is very appreciated!
Copy link to clipboard
Copied
Can you please clarify how to now insert my field names? I tried with your script but it won't add up. Thanks for your patience

