The showif
tag is used to dynamically display questions, tables, or text when a specified condition is true.
1. Which of the following cities have you visited before?
type: checkbox
1. New York
2. Boston
3. Chicago
4. Denver
5. Los Angeles
2. When was the last time you visited Boston?
type: radio
showif: anyChecked($Q1,2)
1. Within the last month
2. 1-2 mos. ago
3. 3-5 mos. ago
4. 6-12 mos. ago
5. Over a year ago
Tip! The skipif
tag is the opposite of showif
and may be preferable to match logic specified in a client-copy of a survey.
Details
-
showif
can be applied to most widgets and question types, though it should not be applied to blocks, groups, or anew page
widget. Instead include thecondition
tag with these widgets. - The
showif
condition can reference content on the same page or elsewhere within the survey. - A widget with a
showif
tag requires an answer only if it's shown to the respondent. - To always display or hide questions or tables, you can include
showif: always
orshowif: never
on a widget. - Applying
showif: always
will not override other conditions that may be applied to the question or variable.
Additional examples
Using 'showif' with 'showtext'
The showif
tag can be used with the showtext
widget to dynamically display other content such as text, HTML, images, etc. In the following example, the showtext "SW_FAN" will be displayed only if the respondent chooses 'Definitely!' or 'Sort of' in Q3.
3. Are you a Star Wars fan?
type: radio
1. Definitely!
2. Sort of
3. Not really
4. What's Star Wars?
showtext: SW_FAN
text: <p>May the Force be with you. Always.</p>
showif: anyChecked($Q3,1,2)
Displaying table rows or columns
Table rows and columns can include dynamic variable references. To show or hide a table row, place a showif
tag on that row or column definition. In the example below, the second row in T5 will only be shown if the respondent answered '5' or more in Q4.
The start table
widget is required to apply showif
to the row.
4. How long have you been in business?
type: integer
range: 0-60
postfix: years
start table: 5
size: 10
type: text
1. Who is currently your primary distributor?
2. Who was your primary distributor <b>5 years ago</b>?
showif: $Q4 >= 5
end table
The showif
tag can also be used to dynamically show and hide table rows and columns in multi-part tables. In such cases, rows or columns can reference other variables, or other parts within the table. In T8, column 1 is active if the a response of '5' or greater was provided at Q6, and column 3 is active if 'Yes' was selected in Q7.
The ifnotset: 0
tag is included so that when a cell is not displayed in a column, it is autocoded to '0'
6. How long have you been in business?
type: integer
range: 0-60
postfix: years
7. Do you anticipate being in business 5 years from now?
type: radio
1. Yes
2. No
start table: 8
intro: What percent of your usage was insource and outsourced?
type: integer
ap: n
range: 0-100
showcolumntotal: Total {total: 100}
if not set: 0
postfix: %
rows:
1. Insourced
2. Outsourced
--
colid: 1
headings: 5 years ago
showif: $Q6 >= 5
--
colid: 2
headings: Today
--
colid: 3
headings: 5 years from now
showif: $Q7 == 1
end table
Comments
0 comments
Please sign in to leave a comment.