Survey Expert Ryan Farmer observes that many well-known companies aren’t branding their surveys, and discusses why survey design is hyper-important when you want to gather customer feedback.
Scripting Sample: Exclude Option Selected in Previous Question
Please Note:This is a tutorial for SurveyGizmo 2.x users. Currently, the sgapiRemoveOption() function is not functional in SurveyGizmo 3.0 currently and will be addressed soon.
This series is dedicated to showing advanced functionality within SurveyGizmo using the Custom Scripting action (Pro plan or higher). While the tutorials are meant to be portable and easy to insert into your own survey, it will be necessary to understand advanced concepts such as Question IDs. These scripts are provided as-is without additional support for alterations.
This script uses the following question types or actions:
- Either a single select question (radio button or drop-down menu) or multi-select question (checkbox)
- A single select question (radio button or drop-down menu)
Description
This script will take the option selected in the first question and remove that option from the follow-up question on the following page that contains the same list of options. For example:
Q1 SOURCE (radio button): What kind of pet do you have? 1) dog 2) cat 3) fish 4) bird 5) Iguana Q2 TARGET(radio): Which other animal is your least favorite? 1) dog (automatically remove this choice if selected in Q1) 2) cat (automatically remove this choice if selected in Q1) 3) fish (automatically remove this choice if selected in Q1) 4) bird (automatically remove this choice if selected in Q1) 5) Iguana (automatically remove this choice if selected in Q1)
You can also do this with a checkbox question as the source question:
Q1 SOURCE (checkbox): Which kinds of pets do you have (check all that apply)? 1) dog 2) cat 3) fish 4) bird 5) Iguana Q2 TARGET (drop-down menu): Which other animal is your least favorite? 1) dog (automatically remove this choice if selected in Q1) 2) cat (automatically remove this choice if selected in Q1) 3) fish (automatically remove this choice if selected in Q1) 4) bird (automatically remove this choice if selected in Q1) 5) Iguana (automatically remove this choice if selected in Q1)
The Script
%%sourceqid = 2; // SOURCE question id %%targetqid = 6; // TARGET single-select question id (radio, drop-down menu) /************* set flag equal to 1 for SOURCE question as single-select (radio button, drop-down menu) set flag equal to 2 for SOURCE question as multi-select (checkbox) *************/ %%flag = 1; /**** DO NOT ALTER BELOW THIS POINT ****/ if (%%flag == 1){ %%value = sgapiGetValue(%%sourceqid); sgapiRemoveOption(%%targetqid,%%value); } if (%%flag == 2){ %%array = sgapiGetValue(%%sourceqid); foreach (%%array as %%value){ sgapiRemoveOption(%%targetqid,%%value); } }
The Steps
- Create your first question as a single-select question (radio button and drop-down menu) or multi-select question (checkbox)
- On a page following, add your second question
- On the same page as the second question, select Add Action > Custom Scripting Control and paste in the above code
- Alter the script for the proper question IDs
- Alter the script setting for %%flag to the proper value to represent the source question type. The default is the source question is a single-select question.
- Use the Reorder Questions option to place the Custom Script above the second question but on the same page
- Save all changes and test in preview mode
Warnings
The reporting values must be an exact match between the two questions.