Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Constructed list

Hi,

In my survey, I am asking a question about the countries for which the respondent works. I have a list of 36 countries and I would like to "group" them in continents so that the respondent can answer more quickly if he works for a whole continent.

That would mean having for instance:
- Europe
----France
----Spain
----Italy
----Portugal
And if the respondent answers Europe, then the European countries would be automatically ticked.

I hope I am clear enough!
Thanks a lot!
asked Oct 29, 2020 by DBlue
Interesting idea, but it does become a little ambiguous without a third checkbox state representing "mixed."  If a respondent were to uncheck France, I assume we'd uncheck Europe, right?  What happens if the respondent manually unchecks Europe - do we automatically uncheck all the European countries?
1. If the respondent unchecks France, we'd uncheck Europe but at least he saved some time for the checking of all the other European countries.
2. Yes, if he unchecks Europe, then we uncheck all European countries.
> My idea was really to save some time for the respondent, e.g. he works in for all Asian countries except for Nepal, he checks Asia and then he just unchecks Nepal.

Thanks!
Thank you very much Zachary, where should I insert this code? Into a constructed list or directly into my question?
BR.
The question.
Thanks a lot, it works perfectly!

1 Answer

0 votes
Try this out:

<script>
$(document).ready(function(){
    // Params
    var groups = [
        {
            groupItem: 1,
            otherItems: [2, 3, 4]
        },
        {
            groupItem: 5,
            otherItems: [6, 7, 8]
        }
    ];
    
    // Run
    var running = false;
    SSI_CustomGraphicalCheckbox = function(graphical, input, checked) {
        if (running) {
            return;
        }
        running = true;
        var match = input.id.match(/^[% QuestionName() %]_(\d+)$/);
        if (match) {
            var item = Number(match[1]);
            groups.forEach(function(group){
                if (group.groupItem == item) {
                    group.otherItems.forEach(function(otherItem){
                        SSI_SetSelect('[% QuestionName() %]_' + otherItem, checked);
                    });
                }
                else {
                    var allChecked = true;
                    for (var i = 0; i < group.otherItems.length; i++) {
                        if (!SSI_GetValue('[% QuestionName() %]_' + group.otherItems[i])) {
                            allChecked = false;
                            break;
                        }
                    }
                    SSI_SetSelect('[% QuestionName() %]_' + group.groupItem, allChecked);
                }
            });
        }
        running = false;
    };
})
</script>


Currently, item 1 spans over items 2, 3, and 4 and item 5 spans over items 6, 7, and 8.  Lines 4-13 of the script can be updated to alter the group definitions.  Make note of how a comma has to appear after every grouping except the last one.
answered Oct 29, 2020 by Zachary Platinum Sawtooth Software, Inc. (171,950 points)
...