By default, hidden values do not update when respondents go backwards in a survey and change their answers. One way to solve this problem is to remove the Back button on a survey, but that still doesn't ensure that they can't click Back on their browser. If you need to ensure that hidden values get updated, use this script.
The Script
Add a Custom Script action and copy and paste the following code.
- Make sure the action is on a page that follows the question from which the hidden value pulls.
- The hidden value must follow the script but it can be on the same page.
--[[Reset a hidden value when a respondent changes their answers. Place this script above the hidden value you are changing (on the same page) --]] -- The merge code or codes that are going to be evaluated. This is usually the same merge code as that in the hidden value. Update the ID of the merge as needed.
mergeCode = '[question("value"), id="2"]'
-- The ID number of the hidden value you are changing. Update this ID number as needed.
hiddenValue = 4 ---------- Be careful when editing below this line ---------- setvalue(hiddenValue, evaluatemergecodes(mergeCode))
Required Customizations
Change the IDs for the merge codes that are going to be evaluated and the ID of the hidden value.
Admin
— Dave Domagalski on 09/16/2019
@Waellotfy77: Thank you for your question!
In general, you do not need to make a separate script for each merge code/hidden value. Having said that, depending on your specific scenario, you will likely need to create multiple variables to capture the various merge codes.
Our Support team may be able to point you in the right direction depending on your use case:
https://help.surveygizmo.com/help/surveygizmo-support-hours
I hope this helps!
David
Technical Writer
SurveyGizmo Learning & Development
— Waellotfy77 on 09/16/2019
I have more than 1 hidden value on the same page it is necessary to make a separate script for each one or can I put the ID of all the hidden value in the same script
N.B the question ID is the same for all the hidden value