Have an idea?

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

CBC - Different level text

Hi,

I want to show different level text based on level 1 of attribute 1. If level 1 of attribute 1 is shown then level 2 of attribute 4 will have some text else we have to show different text. I tried below code but it doesn't help me.
[% begin unverified perl  
 my $concept = 1;
 my $att1 = CBCDESIGNLEVELVALUE(QUESTIONNAME(), $concept, 1);
 if($att1 == 1) 
 {  
 return "Free for the first year";    
 }  
 else   
 {  
 return "Will be charged";   
  
  
 }  
 end unverified  
 %] 


Please help me
asked Apr 12, 2017 by Abdul Bronze (2,630 points)

2 Answers

+2 votes
I'm not certain if this is possible to do with unverified Perl, but it can definitely be done with JavaScript.  To start, add one of these to attribute 1's first level and add the other to attribute 1's other levels:

<input type="hidden" class="cond" value="conditional1"/>
<input type="hidden" class="cond" value="conditional2"/>


Then attribute 4's second level can be given this code:

<span class="conddisplay" data-cond="conditional1">
    text 1
</span>
<span class="conddisplay" data-cond="conditional2">
    text 2
</span>


(For both of these, you may want to give your levels internal labels to make analysis cleaner.)

Putting this code in your CBC's footer will make it so that your desired texts are displayed only when the "conditional1" / "conditional2" levels appear in the same concept:

<style>
.conddisplay {
    display: none;
}
</style>

<script>
$(document).ready(function(){
    $('#[% QuestionName() %]_div .inner_table > tbody > tr:first-child > td.level_text_cell').each(function(){
        var td = $(this);
        var index = $(td).index();
        $(td).closest('tbody').find('> tr > td:nth-child(' + index + ') .cond').each(function(){
            var val = $(this).val();
            $(td).closest('tbody').find('> tr > td:nth-child(' + index + ') .conddisplay[data-cond="' + val + '"]').show();
        });
    });    
})
</script>
answered Apr 12, 2017 by Zachary Platinum Sawtooth Software, Inc. (147,925 points)
Thanks Zachary for your reply but it doesn't work me. I am not a pro in JavaScript so I couldn't  find what the exact issue is. Eventually we decided to show 2 different attributes using alt-spec.
+1 vote
Have you tried the Conditional Display functionality supported within our CBC software?  It is for showing customized text or graphics based on the occurrence of another level of a different attribute.

Try the Attributes tab within your CBC exercise.  Conditional Relationships... button.
answered Apr 12, 2017 by Bryan Orme Platinum Sawtooth Software, Inc. (175,290 points)
...