Have an idea?

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

How to use Javascript for looking at the design and computign the price to display.

Thanks for your reply.
Referring to the last sentence in your answer, can you please tell me on how to use Javascript for looking at the design of the current concept and computign the price to display.
asked Sep 10, 2012 by Asset (340 points)

3 Answers

0 votes
You might apply some of the CBC-functions in SSI Script to obtain the values needed.

These functions can be used this either in Perl or Javascript.

Please see the help manual for more info.

CBCDesignLevelText (ExerciseName_CBCQuestionName,
  ConceptPosition#, LevelTextPosition#)
answered Sep 11, 2012 by anonymous
0 votes
here's an example from a free format question that I have:
<script type="text/javascript">
var myPrices = new Array();
myPrices[[%CBCDesignConceptValue(XXX_Random1,1 )%]] = [%CBCDesignLevelText (XXX_Random1, 1, 3) %];
myPrices[[%CBCDesignConceptValue(XXX_Random1,2 )%]] = [%CBCDesignLevelText (XXX_Random1, 2, 3) %];

<div id="sku1" style="display:none;float:left;" dandik="[%CBCDesignLevelText (XXX_Random1, 1 , 2) %]">
 <table><!-- SKU table-->
  <tr><!-- SKU picture / tooltip div -->
   <td id="td1" title="[%CBCDesignLevelText (XXX_Random1, 1 , 2) %]" style="margin:0px;padding:0px;height:200px;border: none;">[%CBCDesignLevelText (XXX_Random1, 1  , 1) %]
  <tr><!-- price -->
   <td class="raf">
    <center>[%CBCDesignLevelText (XXX_Random1, 1 , 3) %] TL</center>
  <tr><!-- adet / input text -->
   <td class="fiyat" style="border-bottom:2px solid black">
    <center><input id="FFTASKRandom1_response[%CBCDesignConceptValue(XXX_Random1,1 )%]" name="FFTASKRandom1_response[%CBCDesignConceptValue(XXX_Random1,1 )%]" type="text" size="3"></center>
answered Sep 11, 2012 by Bahadir Ozkurt Gold (16,910 points)
0 votes
What I've done in the past is to add hidden spans in my CBC attributes that contain the price for that level. (or possibly even more than one conditional price for each level with classes identifying the different prices. )

Each CBC exercise was a free format, with each column identified by a specific css class. Then with JavaScript went and added up the prices in each column and displayed to total price in the corresponding cell.

Be aware this does not store the summed price in the dataset however.

var p1 = 0;

//look through each span containing a price (class ="h2p") in column 1 and add them up
$('.c1 .h2p').each(function() {
    p1 += parseInt($(this).html());


//set contents of column 1 price cell to the summed price

$('#c1p').html('<center><b>$' + p1 + ' </b></center>');
answered Sep 11, 2012 by anonymous