goto
routes respondents to a question, labeled group, or page based on a condition being "true." After routing, the survey continues from that point and follows any page or group conditions thereafter.
5. Which of the following brands have you purchased from in the past three months?
type: checkbox
instructions: Select all that apply.
randomize: y
1. Brand 1
2. Brand 2
3. Brand 3
4. Brand 4
5. Brand 5
100. Obvious Fake Brand
99. None of these {exclusive: y} {term: y}
goto: bad
condition: anyChecked($Q5,100)
Tip! If you are creating a group for a single question for the purpose of adding the condition
tag, use the
show if
tag instead. It's concise, simple, and easier to understand.
Details
-
goto
can be used as a tag, element decorator, or standalone widget. - The
goto
widget accepts a question or table ID, page label, or group label as input. Include thecondition
tag to indicate how it is triggered. - As a tag,
goto
is attached to the question or variable the condition is based on.goto
tags require the label or question/table ID to route the respondent to, followed by acondition
decorator starting with an 'if' statement. - Multiple
goto
tags may be attached to a single widget. - As an element decorator, the
goto
directive is executed when the option is selected. No condition is necessary. - Most instances of
goto
are for routing to system groups like "term" or "bad." When routing respondents to term pages, it's better to usetermif
instead ofgoto: term
unless a deferred termination is needed. - If complex logic is required for the
goto
condition — e.g., complex Perl statements — it is recommended to use thegoto
widget.
Caution! goto
overrides group conditions, so it is possible to route a respondent to a group with a condition that is false. However, group conditions are evaluated after every page submission within the group. If the condition is not met, the respondent will be routed out of the group immediately upon the first page submission.
Commonly used tags
Tag | Description |
condition |
Evaluates an expression which must be true to trigger |
onload |
Executes goto on page load instead of page submission. |
Additional examples
Using 'goto' as a tag
To use goto
as a tag instead of a standalone widget, attach it to the question the condition is based on and include a condition
decorator after the routing location. Using our previous example, goto
can be attached to Q5 as shown below.
5. Which of the following brands have you purchased from in the past three months?
type: checkbox
instructions: Select all that apply.
randomize: y
1. Brand 1
2. Brand 2
3. Brand 3
4. Brand 4
5. Brand 5
100. Obvious Fake Brand
99. None of these {exclusive: y} {term: y}
goto: bad {if anyChecked($Q5,100)}
Overriding deferred terminations
A common use case for goto
is to override a deferred termination. A respondent can be terminated before they reach the deferred term point by including goto: term
as a tag or widget along with the appropriate condition.
For example, if a survey uses defer term
to terminate respondents at the 'deferred' page, but respondents under 18 should be terminated immediately at QAGE, add the goto: term
widget and apply the same condition as the termif
tag.
appconfig
singlepage: y
defer term: deferred
AGE. What is your age?
type: integer
range: 1-99
termif: $QAGE < 18 {text: AGE | Under 18} {id: AGE}
goto: term
condition: $QAGE < 18
1. Have you participated in any research on this topic in the past year?
type: radio
1. Yes {term: y}
2. No
2. Do you have any pets in your household?
type: radio
1. Yes
2. No
new page: deferred
text: The rest of the survey continues here.
Caution! In the scenario above, it's important to use goto
as a standalone widget so that the respondent punches the disp
variable created by the termif
tag first, before being routed out of the survey.
Creating confirmation loops with the 'goto' decorator
Confirmation loops can be created with goto
to verify answers for previous questions and, if need be, redirect the respondent to a previous question to edit their prior response(s).
In this example, respondents who claim to have 20 or more cats and dogs will be shown Q3. If they verify that they did answer the previous questions correctly, they can continue. If 'No' is selected at Q3, the goto
decorator routes the respondent back to Q1 so they can alter their responses for Q1 and/or Q2.
1. How many cats do you live with?
type: number
datatype: whole
size: 3
2. How many dogs do you live with?
type: number
datatype: whole
size: 3
3. You indicated you have 20 or more pets living with you. Is that correct?
showif: $Q1 + $Q2 >=20
type: radio
1. Yes
2. No {goto: Q1}
Comments
0 comments
Please sign in to leave a comment.