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:

--Denver
--Kansas City
--Oakland
--San Diego
--New Orleans
--Carolina
--Tampa Bay
--Atlanta

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

AFC West
--Denver
--Kansas City
--Oakland
--San Diego

NFC South
--New Orleans
--Carolina
--Tampa Bay
--Atlanta


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">
$(document).ready(function(){
    $('#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>');
})
</script>


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)
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)
Randomize()

List 2:
ADD (Q18MasterList,4,6)
Randomize()

List 3:
ADD (Q18MasterList,7,12)
Randomize()

List 4:
ADD (Q18MasterList,13,17)
Randomize()

List 5:
ADD (Q18MasterList,18,20)
Randomize()

List 6:
ADD (Q18MasterList,21,23)
Randomize(21,22)

Final List that I am using in the question:
Q18List:

ADD(Q18List1)
ADD(Q18List2)
ADD(Q18List3)
ADD(Q18List4)
ADD(Q18List5)
ADD(Q18List6)



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) {
    ADD($list);
}
End Unverified


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

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
...