Have an idea?

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

ACBC show price before discount

we are using a summed pricing to place a discount on price- so our range for summed price goes from 0% above to 40% below. We also want to show respondents what the price is if it were a 0% discount (so just the sum of all of the attribute levels summed price values) is there a way to do this?
asked Aug 24, 2018 by Jackie

1 Answer

0 votes
This is possible, but it takes a little effort.  To start, you'll have to add HTML like this to each non-zero price level in your ACBC:

<input type="hidden" class="acbcPrice" value="100"/>


You will need to replace "100" with the current level's price.  (Feel free to give the level's an internal label to keep the HTML from showing up in analysis.)

Now add this script to your Screener question:

<script>
$(document).ready(function(){
    var clone = $('#[% QuestionName() %]_div .inner_table > tbody > tr:nth-last-child(2)').clone();
    $(clone).find('> td:first-child').text('Price 2:');

    for (var col = 2; col <= $('#[% QuestionName() %]_div .inner_table > tbody > tr:first-child > td').length; col++) {
        var price = 0;
        $('#[% QuestionName() %]_div .inner_table > tbody > tr > td:nth-child(' + col + ') .acbcPrice').each(function(){
            price += Number($(this).val());
        });
        $(clone).find('> td:nth-child(' + col + ')').text('$' + price);
    }
    
    $('#[% QuestionName() %]_div .inner_table > tbody > tr:last-child').before($(clone));
})
</script>


That should get you started on this.
answered Aug 24, 2018 by Zachary Platinum Sawtooth Software, Inc. (117,475 points)
Thanks Zachary- this works well. I have a couple questions to edit this:
-How can I make the price centered?
-How can I make the price rounded to nearest cents (so 2 decimal places)
-Is it possible to have the row be added as the second to last row instead of the last row?
<script>
$(document).ready(function(){
    var clone = $('#[% QuestionName() %]_div .inner_table > tbody > tr:nth-last-child(2)').clone();
    $(clone).find('> td:first-child').text('Price 2:');

    for (var col = 2; col <= $('#[% QuestionName() %]_div .inner_table > tbody > tr:first-child > td').length; col++) {
        var price = 0;
        $('#[% QuestionName() %]_div .inner_table > tbody > tr > td:nth-child(' + col + ') .acbcPrice').each(function(){
            price += Number($(this).val());
        });
        $(clone).find('> td:nth-child(' + col + ')').text('$' + price.toFixed(2));
    }
    
    $('#[% QuestionName() %]_div .inner_table > tbody > tr:nth-last-child(2)').before($(clone));
})
</script>


You want to horizontally center one of the price values in the table?
Thanks! This works. Yes I want the dollar amounts to be horizontally centered instead of left-aligned.
<style>
#[% QuestionName() %]_div .inner_table > tbody > tr:nth-last-child(2) > td:not(:first-child) .level_text,
#[% QuestionName() %]_div .inner_table > tbody > tr:nth-last-child(3) > td:not(:first-child) {
    text-align: center !important;
}
</style>
Thanks! Is it possible to customize the formatting of the price label? For example:
<b>List Price <i>(price before discount)</i></b>
Try replacing this:

.text('Price 2:')


with this:

.html('<b>Formatted label</b>')
...