Pular para o conteúdo principal
Base de Conhecimento da FocusVision

Hidden Questions

This article details the process for hiding survey questions from respondents.


Hidden questions are survey questions not shown to respondents that are used to track data either through pre-loaded sample variables, or data points calculated within the survey. Data stored in these questions can later be used for building in-survey logic or for splitting reports.

Hidden questions function similarly to autofill elements, but allow for more complicated logic to be used when punching targeted questions.

1: Hiding a Question

Almost any question can be hidden. To hide a question, you will need to add the where attribute and set it to execute. The where attribute controls where a question will appear in a survey, and setting it to execute value will hide the question.

Click here to learn more about the where attribute.

1.1: In the Survey Editor

In the question options menu on the right side of the screen, first select "where" from the “More Options” drop-down menu:

This will add the where attribute to the list of options that are available to edit. Then, enter “execute” in the where text field:

1.2: In the XML Editor

Add where="execute" to the question tag:

 <title>Age Group Tracking</title>
 <comment>Select one</comment>
 <row label="r1">18-24</row>
 <row label="r2">25-34</row>
 <row label="r3">35-44</row>
 <row label="r4">45-54</row>
 <row label="r5">55+</row>

1.3: End Result

Hidden questions will only appear during testing and in the data. If you would like to view your hidden question to ensure that it is getting punched correctly, select "Testing a Survey With Tools" in the test environment page and toggle "QA codes" on. Then look for a question with a crumpled paper background, similar to the below: 

Hidden questions will always appear on this background and include a message about not being displayed to live respondents. You will not see these pages while testing in "Show Respondent View" mode or in a live survey.

2: Populating a Hidden Question

Once you have hidden a question, you will need to make it populate. Hidden questions can be populated using some simple Python code inside of an exec block. To populate your hidden question, change its value attribute using the Python.val command within the question tag.

For example, if you would like to set question "Q1" to a value of 1, you can use the following code:

Q1.val = 1

Depending on the question type, this value can be set to something else. See below for different ways to populate a hidden question depending on its question type.

2.1: Populating a Single-Select Question

2.1.1: One-Dimensional Single-Select Questions

To populate a hidden single-select question, assign its value to the index of the row that you are looking to punch. Since row indexes are zero-based (in the above example, r1 has an index of 0), you will need to input one integer below your target value.

For example, if you want your hidden question to punch r3, you can add the following code:

q2.val = 2

However, there are some issues with setting the index numerically. For instance, you may end-up assigning an index different than the intended row if you change row positions. To ensure that the correct index is assigned, you can instead specify your question and row objects using the following notation: qxx.rxx.index. This will return the row’s index, which can then be used for assigning. 

Using the above example, you can make the following modifications:

q2.val = q2.r2.index

2.1.2: Single-Select Grid

To populated a single-select grid question, assign each row a value that corresponds to the column index that would have been selected. This slight modification from the one-dimensional single-select question might appear as follows:

q2.r1.val  = q2.c1.index

If you are using grouping="cols", the value assignment method changes, and you will need to punch the index of the selected row into the column value:


2.2: Populating a Multi-Select Question

2.2.1: Single-Dimensional

Multi-select questions are populated differently from single-select questions. In multi-select questions, you can punch multiple rows at the same time and each row can have one of two possible values:1 for checked and 0 for unchecked. This means that you cannot assign a single value to the question, and will instead need to assign a value to each of the question's rows separately. 

For example, to populate all checkboxes in the question below:

You would need to loop through each row and assign its value separately:

for eachRow in q3.rows:

2.2.2: Multi-Select Grid

To populate multi-select grid questions, you need to target a specific cell in your grid question and assign it a value of 1 or 0. You can do this by referencing both the row and the column of your chosen cell, as shown in the example below:

q3.r1.c1.val  = 1

Similarly, if you want to punch all answer options in a multi-select grid, you need to traverse both the rows and columns of your question.

For example, to punch all options in q3, you can use the following code:

for eachRow in q3.rows:
   for eachCol in q3.cols:
       q3.rows[eachRow.index].cols[eachCol.index].val = 1

2.3: Populating a Text Question

Text questions are simpler to populate than single and multi-select questions, as you do not need to specify any rows to punch. To populate a text question, you can just assign a value directly to the question.

For example, if you are using the question below to track a respondent’s name:

You can use the following exec block to set “John” as the name for one of your respondents:


When assigning any text to a text question, the text value must be assigned as a string type variable or a quoted string:


Note: You can use q4.r1.val if you have a text question with multiple rows.

2.4: Populating a Number Question

Number questions follow the same rules as text questions, with the exception that you will need to assign a number of integer type variable instead. 

For example, if you are tracking respondent age using the number question below:

You can use the following exec block to assign 20 as the age for a respondent:


Alternatively, if you have a number stored in a variable, you can use that variable for the assignment statement:


Note: Number questions only accept whole numbers by default. If doing calculations, it is better to convert your variable to an integer before assignment:


2.4.1: Populating a Decimal Question

Number questions that have “Allow Decimals” enabled accept both whole numbers and decimal values. To populate one of these hidden decimal questions, you can use theexec block below:

  • Este artigo foi útil?