Skip To Content

Form expressions

Expressions can be used in your survey to control the default behavior of questions. A question, or a group of questions, can be hidden and revealed based on previous answers using expressions in the relevant column. A question hidden through an expression in the relevant column cannot submit any data in the survey, and any data previously entered into the field is deleted.

Expressions can also be applied to the readonly column, which can disable input to a question or group based on the result of the expression. The required column also supports expressions, allowing the survey to force the user to answer a question only under specific conditions.

Note:

Readonly expressions are not currently supported in the web app.

Previous questions must always be referred to in expressions with the format ${field_name}.

Simple expressions

The simplest way to use one of these expressions is to change the behavior or visibility of a question, unless a particular answer was given previously. For example, this expression will check if the answer to the previous question is true:

${previous_question} = 'true'

This example will check if the answer to the previous question was greater than or equal to 100:

${previous_question} < 100

select_multiple questions hold their values differently than other question types, with each checked answer entered in the order it was selected, separated by commas. For example, selecting answers A and B, in that order, will present the response as A,B. To use a select_multiple question as part of an expression, you'll need to use the selected command. This example checks if the user answered the previous question with 'A', and will function regardless of other answers chosen:

selected(${previous_question}, 'A')

The count-selected command counts the number of options that have been selected in a select_multiple question, providing a number to use as an operator. This example checks if the previous question had more than two choices selected:

count-selected(${previous_question})>2

Mathematical expressions

This example combines multiple operators and questions:

${previous_question} + ${other_previous_question} <= 100

When using mathematical operators, be aware that sometimes you may need to cast values into numbers. In the previous example, it was assumed that previous_question and other_previous_question were integers or decimals, but what if the question types were strings? Then you cast them as follows:

int(${previous_question}) + int(${other_previous_question}) <= 100

You can also perform mathematical expressions on date questions, which are saved as Epoch time, the amount of milliseconds passed since January 1, 1970. This expression reveals a question only if the answer to the previous question is more than two weeks before today:

if( ${previous_question}='',false,today() - ${previous_question} > 1000*60*60*24*15)

Regular expressions

Regular expressions can be used in the relevant, readonly and required columns to alter the behavior of a question, unless the string provided by another question is in a given format. This example, when placed into the relevant column, will only display a question if another question has been answered with only letters:

regex(${question},'[A-Za-z]')

For more information on regular expressions, see Formulas.