Search code examples
surveyjs

Surveyjs - change title of question on condition


I am working with SurveyJS to create a survey. The answer of the first question can be either TRUE or FALSE (the user can choose by using a radio button). I would like to set the title of the second question depending on the answer given to the first question. In particular, the title of the second question should be 'What is your age?' if the first question has been answered TRUE, 'How old are you?' otherwise. I read a bit of the SurveyJS documentation, but I didn't find a way to do that. Do you have any suggestion? Thank you in advance!


Solution

  • You can use a calculated value:

    {
     "pages": [
      {
       "name": "page1",
       "elements": [
        {
         "type": "radiogroup",
         "name": "question1",
         "choices": [
          "item1",
          "item2"
         ]
        },
        {
         "type": "checkbox",
         "name": "question2",
         "title": "{var1}",
         "choices": [
          "item1",
          "item2",
          "item3"
         ]
        }
       ]
      }
     ],
     "calculatedValues": [
      {
       "name": "var1",
       "expression": "iif({question1} = 'item1', 'First item', 'Second item')"
      }
     ]
    }