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'd be awesome for the radio button question that follows to already be selected. With this quick script, it'll do it for you automatically!

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.

2. Edit the radio button question then click on Piping/Repeat. You'll use the Pipe Into option, selecting the checkbox question from the previous page. Save your choice.

3. 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');
}
});

Save the action. The page with the script and radio button should look like this once you have it set up:

Now, if it's all set up correctly, when only one option is selected, you'll see 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();
}
});

Basic Standard Market Research HR Professional Full Access Reporting
Free Individual Team & Enterprise
Feature Included In