Urgent help needed: How do I validate a numeric response against that of a prior question?


Has anyone created custom script to validate the response to a second question against that from a prior question? For example:

Q1: “How many glasses of water did you drink in the past week?”

Q2: “How many glasses of water did you drink in the past month?”

The answer to Q2 must be larger than or equal to the answer in Q1.  I have searched for an answer but the only reference I find is that a custom script must be created although I have not found any specific guidance. Unfortunately, after reaching out for paid programming assistance, we have not yet received a response.  We are on an urgent client deadline, so I truly appreciate any help anyone might be able to provide.

Thank you in advance!!

Paritosh Mehta99759 answered

    Hi Christi,

    Assuming you have Q1 on 1st page and Q2 on 2nd page, create a blank page and paste the following custom script, which will check if Q2 is greater than Q1. If it is, the survey will move ahead to the next page (4th page which is Q4), if not it will jump back to 2nd page and will show an error message. For the error message, just add a text instruction on the 2nd page (and add an appropriate error message) and make it hidden by default and the script will display it if the condition is not met (please change the question ID’s): 


    %%VarQ1 = 1;  // Q1's Question ID<br />%%VarQ2 = 2; // Q2's Question ID<br />%%VarErrorMessage = 3; // ID for Text Instruction where you have put the error message<br />%%Q2Page = 2; // The page ID where Q2 is.
    %%NextPage = 4; // The page ID for Q3 or whatever next question you have.
      if (%%VarQ2 < %%VarQ1)
        sgapiHideQuestion(%%VarErrorMessage,False);<br />    sgapiJumpToPage(%%Q2Page);
      }<br /><br /><br />Let me know how this works out for you.<br /><br />Thanks<br />Paritosh<br />paritosh@ae-research.com
    Paritosh Mehta99759 edited answer


      Question stats

      • Active
      • Views5615 times
      • Answers1 answer
      • Followers1 follower