How can I validate an answer based on the value of a previous question?

  • Focha
    Asked on March 20, 2017 at 6:43 PM

    Hi all,

    How can I validate an answer based on previous question?

    Example:

    How many hours do you spend watching TV?

    How many of those hours do you spend watching sports channel?

     

    Now you see, the numeric value of the 2nd answer cannot be greater than the 1st one.

     

    How can I do that?

     

    Thank you for your support.

    Kind regards,

    Carlos

  • Kevin Support Team Lead
    Replied on March 20, 2017 at 10:52 PM

    Yes, it is possible to achieve it using conditions, to do it, you will need to use the number field and add some text just as alert to your user:

    How can I validate an answer based on the value of a previous question? Image 1 Screenshot 30

    Once this is done, you need to add a condition to evaluate the fields and show the message based on user's answer, if the second question is greater than the first one then the text displays: 

    How can I validate an answer based on the value of a previous question? Image 2 Screenshot 41

    You need to use the number fields, otherwise the "Greater Than" statement will not be shown. 

    This guide will also provide you with more details about how to show/hide fields based on user's answers: https://www.jotform.com/help/316-How-to-Show-or-Hide-Fields-Base-on-User-s-Answer 

    Here's also a testing form where you can see how it works: https://form.jotformpro.com/70789053229968 

    Should you have any question, please let us know. 

  • Carlos
    Replied on March 21, 2017 at 7:51 AM

    Ok, I understand the process, but that does not prevent the submitter to continue to the next page.

    Is there any way of preventing that?

    Kind regards.

  • Kevin Support Team Lead
    Replied on March 21, 2017 at 10:32 AM

    You could include the page break buttons in the conditions, submit button may be also included if you would want it too. 

    Then if the second field's value would be greater than the first one the page break buttons will be hidden and the message will be shown. 

    Here's the modified condition:

    How can I validate an answer based on the value of a previous question? Image 1 Screenshot 20

    I've updated my sample form, you could take a look to the result here: https://form.jotformpro.com/70789053229968 

    Hope this helps. 

  • Carlos
    Replied on March 22, 2017 at 10:58 AM

    Ok, now I understand! It seems truly a matter of logic.

    Thank you and well done. I now understand a bit more of the system.

    Kind regards.