Script: Triggers - Radio Question Response Displays Text Question
Answering a 'Radio Question' can display a follow-up 'Text Question' on the same page
Background
You may want to have a Radio Question and a follow-up Text Question (open end) on the same page. The stipulation is you want the Text Question to appear once the Radio Question has been answered. This article will show you how to set this up.
Instructions
Step 1: 'Radio' Question
- Add your 'Radio Question' as needed
- See article: Standard Question: Radio items (Single Select)
- In the Overall Question Settings do the following:
- See article: Overall Question Settings
- Turn OFF the "Hide on submit if valid" setting. This will leave the question on the screen should the other questions on the page get an error message.
- Add the following code to the 'Source Code Editor' of the 'Footnote' field
- See article: Source Code Editor
- Add the code below:
<script> /* NOTE: REPLACE "Q2" WITH THE RADIO QUESTION NUMBER */ /* NOTE: REPLACE "Q3" WITH THE TEXT QUESTION NUMBER */ jQuery(function() { if (!jQuery(".cm-question[data-qnum=Q2] input:radio").is(":checked")) { jQuery("#question-Q3").hide(); } jQuery(".cm-question[data-qnum=Q2] input:radio").change(function() { /* NOTE: UPDATE THE FORMULA IN THE NEXT LINE BELOW WHICH WILL SHOW THE FOLLOW-UP */ if (jQuery(".cm-question[data-qnum=Q2] input:radio:checked").attr("data-name") == "1") { jQuery("#question-Q3").show(); } else { jQuery("#question-Q3").hide(); jQuery(".cm-question[data-qnum=Q3] textarea").val(""); } }); }); </script>
Step 2: 'Text Fields' Question
- Add your 'Text Fields' as needed
- See article: Standard Question: Text Fields
- In the Overall Question Settings do the following:
- See article: Overall Question Settings
- Turn OFF the "Hide on submit if valid" setting. This will leave the question on the screen should the other questions on the page get an error message.
- Toggle off the 'Require a Response' option. This will allow you to get by the page without answering the open end question.
- You may also want to add a 'Custom Validation' in order to make sure the 'Text Fields' question is answered under the appropriate circumstances
- See article: Custom Validations