Revealing and hiding questions |
Sometimes it is useful to present one question to the respondent and, depending on how they answer, to present additional follow-up questions.
If all these questions are simple and short enough to be presented on one page, using the DisplayOrHide question style is a simple and very effective to do so.
The DisplayOrHide question style displays or hides groups of questions on the same page depending on the value of another question.
Respondents can toggle between the question groups, and values are removed from inappropriate questions. See the Examples place.
For example, a single choice radio button question named "smoke" could have value yes, no, and maybe. A drop down question named "smoke_frequency" asks participants how often they smoke. A text area question named "comment" asks respondents to elaborate. When the respondent first sees the questionnaire, they only see the smoke question and the others are hidden. If they click on yes or maybe, the drop down appears. If they click on no, the drop down disappears and the comments box appears instead.
To achieve this effect, first create the questions as described.
Then create a question with style DisplayOrHide, using the HTML question type.
In the "Formula" field, enter the following:
The formula is created as follows. Each line is ended with a semicolon. Spaces can be used freely between items; smoke, smoke_frequency, and comments are question names.
The first line of the formula is the name of the condition question, whose value determines what to display and what to hide.
The lines that follow indicate a list of values, comma-separated, to the left of the equal sign, and a list of affected questions on the right of the equal sign, also comma-separated.
When the respondent clicks on the condition question and selects a value listed to the left of the equal sign, the affected questions listed on the right side are displayed. When the respondent clicks on a value that is not on that line, the affected questions on the right side are hidden. All values that are entered into the questions that are becoming hidden are removed.
"-other" and "-none" are special values for when the user clicks on the Other button and for when the user clicks on the None button (in radio buttons only).
When the page with these instructions is first presented, all affected questions listed in all the choices are hidden by default. This can be changed by adding a colon after the question name on the first line and adding a keyword:
smoke: noneshow;
Note that a colon has been added to the question name, rather than an equal sign. With the keyword "noneshow", all questions are displayed when the respondent has not made a choice, rather than being hidden.
The list of questions to the right of the equal sign may contain just one question name, or a list of several question names separated by commas, like this:
yes = smoke_frequency, reason_for_smoking, attempts_to_quit_smoking ;
It can also contain a range of question names, so that all questions between the first and the last are included, like this:
yes = smoke_frequency - attempts_to_quit_smoking ;
Multiple conditions can be set up in the same pattern. The first line indicates the question name of the condition; subsequent lines indicate what questions to display or hide for different values of the condition.
When these formulas are used with radio buttons that include an Other option, clicking on Other will hide all questions listed. By adding the "othershow" keyword to the initial line, this behavior is disabled. It is also possible to specify what questions to display when Other is selected by using the special value "-other" ( the word other preceded by a dash) on the left side, before the equal sign, like this:
no, -other = comments;
Similarly, a special value "-none" can be used on the left side, before the equal sign, to specify what questions to show when the respondent has not made a choice
When used with a set of one or more check boxes, each values of the conditional question displays or hides the affected question independently of the other values.
The conditional question whose value determines what question to display or hide can be a radio button, a drop down, or a check box question.
To display or hide an entire matrix, refer to it as matrixname_ . A matrix's question names start with a matrix name; use that name with an underscore. Individual matrix rows can be displayed or hidden using the name of the question in that row, such as rate_service. It is not possible to display or hide just the header row or the explanatory text above the matrix.
To display or hide an entire grid, refer to it as gridname_. A grid's question names start with a grid name; use that name with an underscore. Individual grid rows cannot be displayed or hidden. However, individual questions in the grid can be, using the name of the question in that cell.
Required questions. Affected questions can be "required". When a required question is hidden, values and choices are removed from the hidden question.