The range
tag allows Survey Programmers (SPs) to define a permitted numeric range for a response, which can even include negative numbers and decimals. If the condition on a question with a range
tag is not met, a generic warning message appears: 'Please enter a number between x and y'.
Syntax
The range
tag can accept a lower/upper bound or a variable, as well as a variety of operators (<, >, +, etc.), negative and positive values, integer and decimal values, and piped-input.
# basic range with upper and lower bounds ("end points")
1. Range of values accepted type: number / integer range: Lower bound - Upper bound # If 'number', decimals are allowed; if 'integer', no decimals are allowed
# range with only an upper bound (max) 2. Values up to given number type: number / integer range: <= Upper bound # '<' operator is also valid
# range with only a lower bound (min) 3. Values below given number type: number / integer range: >= Lower bound # '>' operator is also valid
# range based on previous response 4. Values below a variable value type: number / integer range: <$Q3
Tags
The range
tag must always accompany a type
tag or datatype
tag in a question or table since it only sets limits and doesn't specify input type. Below are the tags commonly used with the range
tag.
Tag | Description |
---|---|
type: number |
This question type allows positive and negative whole numbers and decimals. |
type: integer |
This question type allows positive and negative integers (including '0'). |
datatype |
Use with
|
maxlength |
If used, will specify the maximum number of digits (or letters) accepted in a response. |
size |
If used, will specify the width of the text field for the response. The width is specified in ems. |
range_message |
If used, will alter the default error message that is displayed if a respondent provides a response that is outside of the specified range. |
Tip! The type: number
and type: integer
tags include built-in (default) text field sizing. However, you can apply the size
tag with the range
tag whenever the default sizes need modifications.
Examples
Range of values
If using range
on its own, the upper bound of the range will be used to determine a "reasonable" size for the text field. You can use the size
tag to limit the width of the free entry space, or use the maxlen
tag to limit the number of digits allowed as needed.
Upper or lower bounds
When setting a limit/upper bound on the largest allowed input value, such as range: < 200
, the range
tag's default text field sizing is applied. Specifying datatype: whole
means accepted values must be greater than or equal to 0.
Using a space between the greater than/less than sign and the limit value is optional.
When using only an upper or lower bound, the default error message will be specific: 'Please enter a number greater than n' or 'Please enter a number less than n.'
Variable interpolation
Additionally, variable values can be interpolated, allowing SPs to incorporate earlier respondent answers into range validation. In the example below, the range for Q4 is dictated by the response in Q3, and Q4's response must not exceed the response in Q3.
Changing the range validation failure message
To change the error message that appears when respondent input fails to meet the range criteria, use the range_message
tag.
Comments
0 comments
Please sign in to leave a comment.