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