Question T18340
Visible to All Users

How to change question title dynamically based on selected value from dropdown.

created a year ago

"I have two dropdowns: one is 'module' and the other is 'select'. My requirement is that when I select values from the module dropdown, the selected values should become the title of the select dropdown. How can I achieve that?"

JSON
{ "logoPosition": "right", "pages": [ { "name": "page1", "elements": [ { "type": "panel", "name": "panel1", "elements": [ { "type": "text", "name": "title", "title": "Title", "hideNumber": true, "isRequired": true }, { "type": "text", "name": "description", "title": "Description", "hideNumber": true, "isRequired": true }, { "type": "dropdown", "name": "module", "title": "Module", "hideNumber": true, "choices": [ { "value": "vehicle", "text": "Vehicle" }, { "value":"game", "text":"Game" } ] }, { "type": "dropdown", "name": "select", "visibleIf": "{module} notempty", "title": "{moduleTitle}", "hideNumber": true, "defaultValueExpression": "getSelectedText('module')", "choices": [ { "value": "cars", "text": "Car" }, { "value": "bike", "text": "bike" }, ] } ] } ] } ], "questionErrorLocation": "bottom" }

Answers approved by surveyjs Support

created a year ago

Hello,
To show the display value of a selected 'module' option, define a question title as follows: "title": "{module}".

JSON
{ "type": "dropdown", "name": "select", "visibleIf": "{module} notempty", "title": "{module}", "hideNumber": true, "defaultValueExpression": "getSelectedText('module')", "choices": [ { "value": "cars", "text": "Car" }, "bike" ] } ] }

Consider the updated survey JSON:

JSON
{ "logoPosition": "right", "pages": [ { "name": "page1", "elements": [ { "type": "panel", "name": "panel1", "elements": [ { "type": "text", "name": "title", "title": "Title", "hideNumber": true, "isRequired": true }, { "type": "text", "name": "description", "title": "Description", "hideNumber": true, "isRequired": true }, { "type": "dropdown", "name": "module", "title": "Module", "hideNumber": true, "choices": [ { "value": "vehicle", "text": "Vehicle" }, { "value": "game", "text": "Game" } ] }, { "type": "dropdown", "name": "select", "visibleIf": "{module} notempty", "title": "{module}", "hideNumber": true, "defaultValueExpression": "getSelectedText('module')", "choices": [ { "value": "cars", "text": "Car" }, "bike" ] } ] } ] } ], "questionErrorLocation": "bottom" }

Thanks