Update Hidden Values if Answers Are Changed

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!

Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

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 those vital hidden values get updated, we have a quick script for you!

Add a Custom Script action and copy and paste the following code. Make sure the action follows the question from which the hidden value pulls. The hidden value can be anywhere in the survey in relation to the script, even the same page!

/*
Free script provided by Jake and SurveyGizmo
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 as what is in the hidden value
%%mergeCode = '[question("value"), id="2"]';
// The ID number of the hidden value you are changing
%%hiddenValue = 3;

/*
---------- Be careful editing below this line ----------
*/

sgapiSetValue(%%hiddenValue, sgapiEvaluateMergeCodes(%%mergeCode));

The pieces you need to change are the IDs for the merge codes that are going to be evaluated and the ID of the hidden value. to update. You can find the IDs for these elements in the right hand corner of every question or action. Once you have this setup, it should look something like this:

Scripting and Other Custom Solutions

We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.

If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for SurveyGizmo features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our Programming Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!