Copy link to clipboard
Copied
Hi, I have a document I am preparing and one of the form fields essentially adds up 5 other fields (percentages); is there a way I can force that field to equal 100%? Perhaps an error message can appear if they are over or under so they will be alerted to go back and fix it?
If this makes the question easier to understand ~ I need employees to describe tasks that equal 100% of their daily tasks. How I have it set up now they can go over or under 100% and I would like to have an alert for them. I have never used Adobe Acrobat DC but certainly this can be done (?).
Thanks!
Tracy
Copy link to clipboard
Copied
This code should do the trick (I assumed the fields are named Perc1 to Perc5... You can change it to match their actual names, of course):
if (event.value>100) app.alert("Warning! The combined value must not exceed 100%.",1);
else {
if (this.getField("Perc1").valueAsString!="" && this.getField("Perc2").valueAsString!="" && this.getField("Perc3").valueAsString!=""
&& this.getField("Perc4").valueAsString!="" && this.getField("Perc5").valueAsString!="" && event.value!=100) {
app.alert("Warning! The combined value must equal 100%.",1);
}
}
Copy link to clipboard
Copied
So it's allowing me to have an error message saying "the value must be greater than or equal to 100 and less than or equal to 100".
But it isn't allowing me to put a custom note in that explains it better. Is there a way I can edit the error message?
Copy link to clipboard
Copied
As the custom validation script of the field you can use something like this:
if (event.value!=100) app.alert("Insert your custom message here.",1);
Note that this is probably not a good idea, because this message will appear each time the user edits one of those fields... You might want to add a condition that checks that all the fields are filled-in first before showing it, and/or if the value exceeds 100, which is always wrong.
Copy link to clipboard
Copied
How can I add a condition that checks for those things? I have tried so many things with the validation fields trying to get the warning to only show up at the end to no avail.
Thank you for getting back to me.
Copy link to clipboard
Copied
This code should do the trick (I assumed the fields are named Perc1 to Perc5... You can change it to match their actual names, of course):
if (event.value>100) app.alert("Warning! The combined value must not exceed 100%.",1);
else {
if (this.getField("Perc1").valueAsString!="" && this.getField("Perc2").valueAsString!="" && this.getField("Perc3").valueAsString!=""
&& this.getField("Perc4").valueAsString!="" && this.getField("Perc5").valueAsString!="" && event.value!=100) {
app.alert("Warning! The combined value must equal 100%.",1);
}
}
Copy link to clipboard
Copied
I just saw this ~ trying now! Thanks!
Copy link to clipboard
Copied
Success! Thank you so much!
Copy link to clipboard
Copied
I'm not sure if you'll even be able to read this, but here is a ss of what I am trying to sum (not necessarily all 6 will be filled in); I feel like this should be so simple but I am stumped!

Get ready! An upgraded Adobe Community experience is coming in January.
Learn more