When piping from a Checkbox question into a Radio Button question, if there's only one option selected from the checkbox, it would be great for the radio button question that follows to already be selected. With this quick script, we can do this automatically!
Setup
- Set up the questions you want to populate, both the checkbox question on one page and the radio button question on a following page.
- Edit the Radio Button question that you are piping into and click the Piping/Repeat tab. You will use the Pipe Into Options feature, selecting the checkbox question from the previous page. Save Question once you are ready.
- On the same page, click Add New Action and select JavaScript.
- Copy and paste the following script into the editor:
$(document).ready(function(){ var radio = $( ":radio" ).length; if (radio == "1") { $(":radio").attr('checked', 'checked'); } });
- Save the action. The page with the script and radio button should look like this once you have it set up:
Now, if everything is set up correctly, when only one option is selected in the checkbox, your radio button question will look like this:
Want to Automatically submit the page if there was only one option and you checked it? Use the below script in a JavaScript Action:
$(document).ready(function(){
var radio = $( ":radio" ).length;
if (radio == "1") {
$(":radio").attr('checked', 'checked');
$("#sg_NextButton").click();
}
});
Admin
— Dave Domagalski on 10/17/2019
@Deborah: Thank you for your question!
I'm sorry for the trouble. The key to the script is to place it on the page that contains the Radio Button question. The Checkbox question must also be on a previous page.
Assuming that this is the case in your survey, if you are using Preview to test this out, make sure that the 'Fire Actions' setting at the top of the preview page is enabled before testing this out.
If you continue to run into trouble, please don't hesitate to reach out to our Support team for assistance.
Best regards,
David
Technical Writer
SurveyGizmo Learning & Development
— Deborah on 10/17/2019
Hi! I am not familiar with scripting, but I need to make most of my surveys do this at least once per survey and am unable to get the above script to work by copying and pasting it, what do I need to do to this code to get it to work? I think I am missing a key piece of the puzzle. Thanks!
Admin
— Bri Hillmer on 03/16/2016
@Emily: I'm so happy to hear it! I'll let Caitlin, the hero that wrote the script, know how excited you are!
Bri
Documentation Coordinator/Survey Sorceress
SurveyGizmo Customer Support
— Emily on 03/16/2016
THIS IS SUPER HELPFUL!! And yes, I'm yelling because I'm so excited! Thanks for the updated script.
Admin
— Dave Domagalski on 08/31/2015
@Minke: Thank you for exploring SurveyGizmo Documentation! It sounds like you would want to hide the radio button question if only one answer is selected in the checkbox question - the best option for this to set question logic on the radio button question based on the number of answers selected in the checkbox.
Here is a link to an article that expands on this:
http://help.surveygizmo.com/help/article/link/checked-logic
Thank you for your question!
David Domagalski
Survey Explorer
SurveyGizmo Customer Support
— Minke on 08/28/2015
This is very useful but then since you'd already know the answer you want to not let the respondent see this page. How do you do that?