Adobe Form Custom Validation Adding to 100%

New Here ,
May 04, 2022 May 04, 2022

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. 

TOPICS
Edit and convert PDFs , JavaScript , PDF forms

Views

139

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
community guidelines

correct answers 1 Correct answer

Community Expert , May 04, 2022 May 04, 2022

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;

Likes

Translate

Translate
Community Expert ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

Is a value of 0 allowed in the fields?

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
community guidelines
New Here ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

No - all fields must have a number over zero

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
community guidelines
Community Expert ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

Display the popup only when all values are greater as zero.

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
community guidelines
Community Expert ,
May 04, 2022 May 04, 2022

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?

 

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
community guidelines
New Here ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

Apologies - they complete 6 lines which are totalled. I've attached a clearer screenshot 

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
community guidelines
Community Expert ,
May 04, 2022 May 04, 2022

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;

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
community guidelines
New Here ,
May 04, 2022 May 04, 2022

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!

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
community guidelines
New Here ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

LATEST

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

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
community guidelines