When Piping into a Radio Button Question, If Only One Option Was Chosen, Select It!

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

  1. Set up the questions you want to populate, both the checkbox question on one page and the radio button question on a following page.
    Source Checkbox Question
  2. 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.
    Pipe Into Options
  3. On the same page, click Add New Action and select JavaScript.
  4. Copy and paste the following script into the editor:
    
    $(document).ready(function(){
    var radio = $( ":radio" ).length;
    if (radio == "1") {
    $(":radio").attr('checked', 'checked');
    }
    });
    
  5. Save the action. The page with the script and radio button should look like this once you have it set up:
    Page with Piping and JavaScript

Now, if everything is set up correctly, when only one option is selected in the checkbox, your radio button question will look like this:

Pre-selected Radio Button

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();
}
});

Basic Standard Market Research HR Professional Full Access Reporting
Free Individual SurveyGizmo Enterprise*
*Excludes Stakeholder
Feature Included In