Script API Tutorial

Skipping question based on NOT selected answer

In the example below we will show how to hide question if a certain alternative was not selected in "Multiple answers" question. It makes sense, for example, when you are conducting brand tracking survey and the Respondent has not chosen the investigated brand from the list.

First we are going to ask Respondent about his/her awareness of some brands (with Brand3 among them). If Brand3 is not chosen by the Respondent, we will skip the next question and finish the survey.

In order to reproduce this example, please undertake the following steps:

Create "Multiple answer" question and add a few brands as alternatives. Create another "Multiple answer" question. Then return to the first question, launch the Script Editor and insert the following script into "OnNextPage script" tab (see the image below):

  • if (!this.get().contains('altCode')) {
  • q['questCode'].hide();
  • }

After that modify the tokens highlighted in red as described in the table below:

altCode Code of the investigated alternative in the first question. In our example this alternative represents Brand3
questCode Code of the second question (which we want to hide in case 'Brand3' was not chosen)

Advanced explanations

The idea of checking whether 'Brand3' alternative was chosen or not is very simple. We get all answers by using "get" function and check whether it contains the code of investigated alternative. If the result of verification is negative ('!' symbol), then we hide the second question.

  • if (!this.get().contains('altCode')) {
  • // get all answers and check whether the function contains the investigated alternative
  • q['questCode'].hide();
  • // if the alternative was not found, the second question will be hidden
  • }

Learn more at CoolTool knowledge base