Dynamically Set and Reset Question Values
Survey questions support API properties that let you automatically set or reset a question's value based on specific criteria. In this demo, these properties are used to copy the shipping address when a user selects "Yes" for the "Shipping address same as billing" question.
Set Question Values Dynamically
To set a question's value based on other answers, assign an expression to the setValueExpression
property. The result of the expression will be used as the question's value. If you want this expression to be evaluated conditionally, use the setValueIf
property to specify the condition. This property accepts a Boolean expression, and when it evaluates to true
, the survey runs the setValueExpression
and assigns the result to the question's value.
Reset Question Values Conditionally
To reset a question's value when a certain condition is met, specify the resetValueIf
property with a Boolean expression. When this expression evaluates to true
, the question's value will be reset to the defaultValue
.
Refer to the survey JSON schema (json.js
file) for code examples.