Have an idea?

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

CBC Conditional Display with Survey Question

In CBC Conditional display, we get option to prepare lookup table using combination of attribute / levels.

Is it possible to use mix of survey questions as well in conditional display like:

If country=1, gender =1, att1 = 1 >> display price A
If country=1, gender =2, att1 = 1 >> display price B

etc

I believe an alternate for this will be changing display using jquery.
asked Apr 27, 2016 by Saurabh Aggarwal Gold (27,705 points)
I don't believe this is possible via Lighthouse's built-in tools.  jQuery seems like the way to go.  I can offer a hand in creating that code if you want the help; I would just need to know what "Position in Concept" you're using for the conditional display.
Trying using jquery for this myself. It would be great if you can help with general code and I can change position of concept.

1 Answer

+1 vote
Here's the code I put in the footer of my CBC:

<script type="text/javascript">
$(document).ready(function(){
    // CBC Design
    var numberOfConcepts = 4;
    
    // Read non-CBC values
    var q1 = [% Q1 %];
    
    // Iterate through each concept
    for (var concept = 1; concept <= numberOfConcepts; concept++) {
        // Read CBC values
        var att1 = $('.cbc > .question_body > table > tbody > tr:nth-child(2) > td:nth-child(' + (concept + 1) + ') > div').text().trim();
        var att2 = $('.cbc > .question_body > table > tbody > tr:nth-child(3) > td:nth-child(' + (concept + 1) + ') > div').text().trim();
        var att3 = $('.cbc > .question_body > table > tbody > tr:nth-child(4) > td:nth-child(' + (concept + 1) + ') > div').text().trim();
        
        // Determine conditional display
        var display = '';
        if (q1 == 1 && att1 == 'lev 1') { display = '1 - 1'; }
        else if (q1 == 1 && att1 == 'lev 2') { display = '1 - 2'; }
        else if (q1 == 2 && att1 == 'lev 1') { display = '2 - 1'; }
        else if (q1 == 2 && att1 == 'lev 2') { display = '2 - 2'; }
        
        // Replace conditional display
        $('.cbc > .question_body > table > tbody > tr:nth-child(1) > td:nth-child(' + (concept + 1) + ') > div').text(display);
    }
})
</script>


This example uses "Top" as the "Position in Concept."  If you want to use a different position, you would need to update the "tr:nth-child" values in lines 12, 13, 14, and 24.

Currently, the code uses a previous question "Q1" and the first attribute to determine the conditional display, but you can modify this by adding more questions near line 7 or by changing the "if" statements in lines 18-21.
answered Apr 27, 2016 by Zachary Platinum Sawtooth Software, Inc. (63,900 points)
...