Here we check which option is selected for Q1 and depending on that we update the value of variable Custom1 with the correct text. If option 5 that is the Other option is selected then the variable Custom1 will get updated with the user input text. To refer to the text entered for the Other option we use: "QuestionCode_OTHER". Hence in the example script, QuestionCode is Q1 to refer the user input in the other option for question Q1.
We are also branching to the next question which is Q2 for each selection. If required we can branch to different questions based on the selection. You can use ${custom1} to display the value stored in the variable Custom1 on the survey. Once updated the Custom1 value can be used anywhere on the survey.
#if (${Q1} == 1)
$survey.updateCustom1("Baseball")
$survey.branchTo("Q2")
#end
#if (${Q1} == 2)
$survey.updateCustom1("Rugby")
$survey.branchTo("Q2")
#end
#if (${Q1} == 3)
$survey.updateCustom1("Soccer")
$survey.branchTo("Q2")
#end
#if (${Q1} == 4)
$survey.updateCustom1("Basketball")
$survey.branchTo("Q2")
#end
#if (${Q1} == 5)
$survey.updateCustom1("${Q1_OTHER}")
$survey.branchTo("Q2")
#end
To redirect the user to a question based on their answer to the current question you can use the script below:
##single select questions
#if(${Q2} == 1)
$survey.branchTo("Q10")
#end
#if(${Q2} == 2)
$survey.branchTo("Q11")
#end
##Multi select questions branching
#if (${Q1_1} == "1" )
$survey.branchTo("Q10")
#end
#if (${Q1_2} == "1" )
$survey.branchTo("Q11")
#end
Here, Q2 is the current question and Q10, Q11 are the questions after Q2.