How to show and hide specific fields based on the Age?

  • Martinez_Micaela
    Asked on May 8, 2024 at 12:29 PM

    Hello, I have a question and would like to know if it's possible to create a condition where if the date of birth is less than 18 years of age a question is shown, but if the age is 18 years or older than the question is show and required to be completed. I understand that this will include multiple conditions to be created but the main one I need assistance will be with the first part "date of birth is less than 18 years of age a question is shown/Hidden"

    Thank You in advance

  • Carlo JotForm Support
    Replied on May 8, 2024 at 1:35 PM

    Hi Micaela,

    Thanks for reaching out to Jotform Support. You can achieve this by setting up two Date fields, using the Form Calculation widget and conditions to show or hide the fields based on the calculated value. Check out the steps and screencast below to see how it's done:

    1. Add two Date Picker fields to your form.
    2. Set the first Date Picker field as Current and the second as the Date of Birth field.

    How to show and hide specific fields based on the Age? Image 1 Screenshot 501681946795 644078abd7e5b  Screenshot 10 Screenshot 61 3. Next, add the Form Calculation widget to perform calculations for age.

    How to show and hide specific fields based on the Age? Image 2 Screenshot 72
    4. Set the calculation for the Form Calculation widget, as shown below:
    floor((Current Date - Date of Birth) / 365)

    How to show and hide specific fields based on the Age? Image 3 Screenshot 83
    5. Finally, use Show / Hide Field conditional logic to show whether the user is under or over the
    age of 18.

    How to show and hide specific fields based on the Age? Image 4 Screenshot 94
    You can also check out my demo form and see if it fits your requirements. You can clone my form to check the conditions and form calculation.

    Give it a try and let us know how it goes.

 
Your Answer