Have an idea?

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

Subheaders within a mutli-select question

Say I want to select which football teams I like to root for and I use the select question. The typical layout would look this this:

--Kansas City
--San Diego
--New Orleans
--Tampa Bay

However, I want to have sub-headers to give it a slight "hierarchy" look:

AFC West
--Kansas City
--San Diego

NFC South
--New Orleans
--Tampa Bay

How can I make this happen in the preformatted select question type. Doing free format works, but if I can mitigate user error is setting up the numeric equivalents, I'd like to explore that.

Preemptive thanks to Zachary and/or Paul Moon as I am sure they'll be the first to respond :)
asked Apr 11, 2016 by WTW_cal Bronze (1,575 points)
I would have supplied a similar solution Justin Luster provided me with a few years ago. This solution, along with Zachary's both work beautifully.

1 Answer

+2 votes
Ha ha.  Looks like I've got Paul beat today.

I would do this with jQuery's 'before' or 'after' functions, like so:

<script type="text/javascript">
    $('#SelectQ_div > .question_body .response_column > div:nth-child(1)')
        .before('<div>AFC West</div>');
    $('#SelectQ_div > .question_body .response_column > div:nth-child(6)')
        .before('<br><div>NFC South</div>');

You can change the "nth-child" value to modify where to place the text in the list.
answered Apr 11, 2016 by Zachary Platinum Sawtooth Software, Inc. (138,150 points)
How can we get this working when using randomized response options.
Two options come to mind, both involving doing the randomization yourself rather than in the select question.  The first option that comes to mind would be to use constructed lists.

You'd start with one big predefined "FootballTeamsList."  Then you'd create constructed lists for each subsection.

ADD(FootballTeamsList, 1, 4)

Then you could create a final constructed list that adds together all of the earlier constructed lists.


Now when you use this list in the select question, the items have been randomized, but are still grouped within their subsections.
The other option for randomizing subsections would be to randomize them yourself with JavaScript.  There are some nice jQuery methods for moving page elements around.  I can help you write that code if you decide this is the right option for you.
Hi Zach,

My client would like to randomize subheaders and randomize items within the subheaders.

I found this post that explains how to randomize items within the subheaders, but I could not find anything on how to randomize the subheaders.

To clarify,
  Subheader 1
Subheader 2

So the client would like the above to appear on the screen like for example

   Subheader 2
       item 4
       item 3
   Subheader 1
       item 2
       item 1

How would I accomplish this?

Thank you
"Subheaders" from the Community Question Library can handle this:


You just need to handle the randomization in a constructed list, then Subheaders will take care of the rest.
Thank you.. I will give it a shot.  I thought it would be more complicated Thanks so much.. you are awesome

I built 7 constructed list and the items under each subheader are randomized.  

But I am not seeing the subheaders randomized.  I have conducted 3 surveys and the subheaders remain in the same order.

How would I accomplish this?

Thank you
What are your constructed list instructions?  Are you observing that your groups of items are appearing in randomized order in your final constructed list?
My constructed list instructions are:

List 1:
ADD (Q18MasterList,1,3)

List 2:
ADD (Q18MasterList,4,6)

List 3:
ADD (Q18MasterList,7,12)

List 4:
ADD (Q18MasterList,13,17)

List 5:
ADD (Q18MasterList,18,20)

List 6:
ADD (Q18MasterList,21,23)

Final List that I am using in the question:


I am observing the items in each group (List) are randomized but not the groups.  They appear in the order of Q18List
"Subheaders" doesn't rearrange items.  It just adds the headers.  Your final constructed list always combines the other constructed lists in the same order, resulting in the behavior you're observing.

Try setting your final constructed list to use these instructions:

Begin Unverified Perl
# Parameters
my @lists = ('list1', 'list2', 'list3');

# Run
my $i = scalar @lists;
while ($i--) {
    my $j = int(rand($i + 1));
    @lists[$i, $j] = @lists[$j, $i];

foreach my $list (@lists) {
End Unverified

Line 3 must be updated with the number of and names of the other constructed lists.

The "subheader" labels are not appearing now.   I tried to take a shot by adding the code:

my @labels = ('Aske for Assitance/Advice', 'Look at Prices/Promotions', 'Find/Buy Product by Brand', 'Look for Information', 'Use my Mobile Device' , 'Other' );

But this didn't work
I did find my error.   The code you provided is PERFECT THANK YOU so much for all of your help you SAVED me a LOT of work  because I was going to add the list in different orders