Script API Tutorial

Filtering answers

Sometimes it's necessary to filter the alternatives in question depending on previous answers.

For example, at first you want to present some brands to the Respondent and then (in the next question) ask about his/her awareness of those brands.

Here in the first question we want to know the brands of Belgian chocolate our Respondent has ever tasted.

In the second question we ask the same thing about French brands, while in the third one we want our Respondent to rate the satisfaction with the brands selected by him in two previous questions.

Give it a try

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

Go to Questionnaire Editor and create a couple of "Multiple answer" questions. Add the alternatives with product names (you may use the example above as a template)..

Each alternative must have a unique code within both questions (i.e. if your alternatives in the first question have codes '1, 2, 3, 4', the codes of alternatives in the second question should be '5, 6, 7 ...' or 'a, b, c..'. In a word, they must be different from those in the first question)

Create a "Rating" question. Add the combined list of alternatives from two previous questions (verify that the codes of alternatives correspond). Now move to the Script Editor and insert the following script into “Item setup script” tab (see the image below)

this.filter('CodeOfFirstQuestion', 'CodeOfSecondQuestion');

Substitute CodeOfFirstQuestion by the code of your first question and CodeOfSecondQuestion - by the code of your second question.

Check the results!

Learn more at CoolTool knowledge base