Copy link to clipboard
Copied
I have 3 form fields with the 1234.56 format style applied to them. When entering numbers in these fields, they should all equal to 100. Is there a way to block the last form field from entering a number over the total?
Field 1__________
Field 2__________
Field 3__________
= 100.
There is no total amount form field to calculate the sum of those form fields. People can enter whatever number in the form fields, but there should be either a warning or automatically delete the last form field if they enter a number that will equal over 100.
Copy link to clipboard
Copied
So they are entering a percentage, such as 34.5 for 34.5%? What happens if they enter a number >= 100?
What are the field names.
This is a bit tricky, but perhaps the best approach is to use Validation Scripts on each field. This will provide an opportunity to reject the entries on a field by field basis.
// Validation script on Field 1
// First, reject numbers over 100
if(event.value > 100)
{
event.rc = false;
app.alert("Value must be 100% or less");
}
else
{// Test other fields.
var nSum = Number(event.value) + Number(this.getField("Field2").value) + Number(this.getField("Field3").value);
if(nSum > 100){
event.rc = false;
app.alert("The entry in this field brings the total to greater than 100%");
}
}
This could be generalized into a single validation script for all of the fields.
Copy link to clipboard
Copied
So they are entering a percentage, such as 34.5 for 34.5%? What happens if they enter a number >= 100?
What are the field names.
This is a bit tricky, but perhaps the best approach is to use Validation Scripts on each field. This will provide an opportunity to reject the entries on a field by field basis.
// Validation script on Field 1
// First, reject numbers over 100
if(event.value > 100)
{
event.rc = false;
app.alert("Value must be 100% or less");
}
else
{// Test other fields.
var nSum = Number(event.value) + Number(this.getField("Field2").value) + Number(this.getField("Field3").value);
if(nSum > 100){
event.rc = false;
app.alert("The entry in this field brings the total to greater than 100%");
}
}
This could be generalized into a single validation script for all of the fields.
Copy link to clipboard
Copied
WOW! That works! Thank you so much!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now