7 Replies Latest reply: Aug 22, 2013 11:12 AM by GKaiseril RSS

    displaying a message based on age

    JimBobVBA

      have a pdf built in acrobat Pro xi. Have a field called DOB. Data entry is 8 characters with a validation converting 08221964 to 08/22/1964. Want to calculate the age as of system date. If the age is greater than 18, want to display a message "NOTE: Based on the age, further documentation may be required" Selecting OK on the message will allow the form to proceed without any loss of data. Any suggestions on the correct code to accomplish?

        • 1. Re: displaying a message based on age
          MichaelN Community Member

          Have a look at this thread for calculating a person's age:

           

          http://forums.adobe.com/message/5507632#5507632

           

           

          The script can be modified at the end to include something like:

           

               if (age > 18){

               //do something

               }

               else

               //do something else

           

           

          That should get you started.

           

          I hope this helps.

          • 2. Re: displaying a message based on age
            JimBobVBA Community Member

            Have a small problem. The code works fine as a calculation and pops the correct message. However, the same message pops up when data is entered on other date fields that do not have calculations – any thoughts

            • 3. Re: displaying a message based on age
              GKaiseril CommunityMVP

              Do all the date fields have the same name?

               

              Where are you placing your scirpt?

               

              Do you understand the event processing within a PDF form?

               

              Form event processing

              • 4. Re: displaying a message based on age
                JimBobVBA Community Member

                Have only one field on the entire form that calculates age and based on that age pops a message. This is written as a custom calculation script on Child1DOB. Once the message appears once, it continues to appear when I exit any other field. Check and double checked set-up. Appear to be missing something.

                 

                 

                 

                var dobValue = getField("Child1DOB").value;

                 

                 

                 

                if (dobValue!="") {

                 

                 

                 

                    var dob = util.scand("mm/dd/yyyy", dobValue);

                 

                 

                 

                    var today = new Date();

                 

                 

                 

                    var age = today.getFullYear() - dob.getFullYear() - 1;

                 

                 

                 

                    if (today.getMonth()>dob.getMonth()) {

                 

                 

                 

                        age++;

                 

                 

                 

                    } else if (today.getMonth()==dob.getMonth()) {

                 

                 

                 

                        if (today.getDate()>dob.getDate())

                 

                 

                 

                            age++;

                 

                 

                 

                    }

                 

                 

                 

                    event.value = age;

                 

                if (age>18)

                 

                {

                 

                app.alert("This dependent is over the age of 18. Based on your group's eligiblity rules for dependent children, you may need to provide further information in the Special Dependent Information Section below. This section will allow you to designate Full Time Student or Handicapped status.", 1, 0);

                 

                event.rc = false;

                 

                }

                 

                 

                • 5. Re: displaying a message based on age
                  GKaiseril CommunityMVP

                  The calculation events are executed when any field is updated just in case a field update changes the result of the calculation in another field.

                   

                  You need to work out where to put your code or only run it once.

                  • 6. Re: displaying a message based on age
                    JimBobVBA Community Member

                    Thanks for the update. New to custom calculation. How do I force it to only run once and on the specific field. Thanks!!

                    • 7. Re: displaying a message based on age
                      GKaiseril CommunityMVP

                      I would use the "Validation" tab to enter a custom Validation script. This script only runs when the field's value changes.