Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
7

How do I create a message that will pop up if a value does not equal another field?

Community Beginner ,
Feb 23, 2024 Feb 23, 2024

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. 

TOPICS
How to , PDF , PDF forms
642
Translate
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 ,
Feb 23, 2024 Feb 23, 2024

When do you want this message to appear? When field 5 is edited? When fields 1-4 are edited? Something else?

Translate
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 Beginner ,
Feb 23, 2024 Feb 23, 2024

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. 

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

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...

Translate
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 Beginner ,
Feb 23, 2024 Feb 23, 2024

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 

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

I would at least recommend not using a pop-up, then, but something like a (read-only) text field with a warning message.

Translate
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 Beginner ,
Feb 23, 2024 Feb 23, 2024

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.

Translate
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 ,
Feb 23, 2024 Feb 23, 2024
LATEST

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;
Translate
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