How do I create a message that will pop up if a value does not equal another field?
Copy link to clipboard
Copied
I have a form that has 5 numeric fields. I want to create a text box that will populate with an error message if the sum of Fields 1 through 4 do not equal field 5.
Copy link to clipboard
Copied
When do you want this message to appear? When field 5 is edited? When fields 1-4 are edited? Something else?
Copy link to clipboard
Copied
Field 5 is entered 1st - it is the total. Fields 1-4 are the breakout, there for should always equal Field 5. I guess once Field 1 is edited would the the time for the message to pop up.
Copy link to clipboard
Copied
But then it would appear for each field the user fills in... Imagine they enter "100" into field 5, then "10" into field 1, and boom, the error message appears. Then they enter "20" into field 2, and then the same happens. It will be very annoying for them if you do it like that. Alternatively, the error message can appear only when the last field is filled-in (field 4), but then if they enter just 10, 20 and 30 the message will never appear, since they didn't fill in the last field. As you can see, this is tricky to implement correctly...
Copy link to clipboard
Copied
The problem is they may not use all of the fields. Usually they do only use field 1. That is why I'm thinking the message comes up right away and they have to make fields 1-4 = field 5 to make it go away. I'm not worried about annoying them lol
Copy link to clipboard
Copied
I would at least recommend not using a pop-up, then, but something like a (read-only) text field with a warning message.
Copy link to clipboard
Copied
Yes, that's what I was trying to do. I said pop-up but I meant a text field where the warning message would populate.
Copy link to clipboard
Copied
OK, then create that field and set it up as you want it to appear, with the warning text as its default value.
Then enter this code as the custom Calculation script for it:
var total = Number(this.getField("field 5").valueAsString);
var sum = 0;
for (var i=1; i<=4; i++) {
sum+=Number(this.getField("field "+i).valueAsString);
}
event.target.display = (sum==total) ? display.hidden : display.visible;

