Have an idea?

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

Conjoint questions HTML text modification

Hello,

I've a very simple question, yet still couldn't be able to figure out after trying couple of hours.  

I'm adding another row to the conjoint choice task question with the following code:

<script type="text/javascript">

var price1 = $('tr:nth-child(8) td:nth-child(2) div.level_text').html();

var value1 = parseInt(price1.replace('₺','').replace(',',''));

var euro1 = Math.round(value1 / 7.8);

$('tr:nth-child(8) td:nth-child(2) div.level_text').html(price1+"<br><br>Döviz Karşılığı: ("+euro1+"€)")
</script>

Here, I'm trying to show to EUR value of TRY prices in the extra row mentioned above. To do that, first i eliminate TRY symbol (₺) and comma (,) divide the price with the exchange rate. Then, I want to show the price with comma. For example with this code it shows up €22345, but I want it to be seen as €22,345.

Would you please help me on that?

Huge thanks!
asked Apr 6 by CaEr (430 points)
The "toLocaleString" function may be the easiest option for you.  Try this:

euro1.toLocaleString('en-US')


It's a bit on the advanced side, but you may want to consider "Multi-Currency ACBC" from the Community Question Library.  It's built to be able to handle all sorts of multi-currency requirements for ACBC exercises.  You can download it from here:

https://sawtoothsoftware.com/resources/question-library/multi-currency-acbc
Thanks a lot for your very fast reply, you're a lifesaver!  :)
Hello Zachary,

We are still having difficulties on showing the Euro value of prices in this question. First, let me show you the code we're using (its a little long so please bear with me):

<style type="text/css">
.tool_tip_text {
  outline: none; position: relative;
  min-width: 75px; max-width: 800px;
}
</style>

<script type="text/javascript">

var text = $('tr:nth-child(3) td:nth-child(1) div.label_text').html();
var test = text.includes("Şanzıman");

alert(text);

if (test = true)
{

var price1 = $('tr:nth-child(7) td:nth-child(2) div.level_text').html();
var price2 = $('tr:nth-child(7) td:nth-child(3) div.level_text').html();
var price3 = $('tr:nth-child(7) td:nth-child(4) div.level_text').html();
var price4 = $('tr:nth-child(7) td:nth-child(5) div.level_text').html();

var value1 = parseInt(price1.replace('₺','').replace(',',''));
var value2 = parseInt(price2.replace('₺','').replace(',',''));
var value3 = parseInt(price3.replace('₺','').replace(',',''));
var value4 = parseInt(price4.replace('₺','').replace(',',''));

var euro1 = Math.round(value1 / 9.23);
var euro2 = Math.round(value2 / 9.23);
var euro3 = Math.round(value3 / 9.23);
var euro4 = Math.round(value4 / 9.23);


$('tr:nth-child(7) td:nth-child(2) div.level_text').html(price1+"<i><br><br>(Döviz Karşılığı: "+euro1.toLocaleString('en-US')+"<i>€)")
$('tr:nth-child(7) td:nth-child(3) div.level_text').html(price2+"<i><br><br>(Döviz Karşılığı: "+euro2.toLocaleString('en-US')+"<i>€)")
$('tr:nth-child(7) td:nth-child(4) div.level_text').html(price3+"<i><br><br>(Döviz Karşılığı: "+euro3.toLocaleString('en-US')+"<i>€)")
$('tr:nth-child(7) td:nth-child(5) div.level_text').html(price4+"<i><br><br>(Döviz Karşılığı: "+euro4.toLocaleString('en-US')+"<i>€)")

}

else if (test = false) {


var price1 = $('tr:nth-child(8) td:nth-child(2) div.level_text').html();
var price2 = $('tr:nth-child(8) td:nth-child(3) div.level_text').html();
var price3 = $('tr:nth-child(8) td:nth-child(4) div.level_text').html();
var price4 = $('tr:nth-child(8) td:nth-child(5) div.level_text').html();

var value1 = parseInt(price1.replace('₺','').replace(',',''));
var value2 = parseInt(price2.replace('₺','').replace(',',''));
var value3 = parseInt(price3.replace('₺','').replace(',',''));
var value4 = parseInt(price4.replace('₺','').replace(',',''));

var euro1 = Math.round(value1 / 9.23);
var euro2 = Math.round(value2 / 9.23);
var euro3 = Math.round(value3 / 9.23);
var euro4 = Math.round(value4 / 9.23);


$('tr:nth-child(8) td:nth-child(2) div.level_text').html(price1+"<i><br><br>(Döviz Karşılığı: "+euro1.toLocaleString('en-US')+"<i>€)")
$('tr:nth-child(8) td:nth-child(3) div.level_text').html(price2+"<i><br><br>(Döviz Karşılığı: "+euro2.toLocaleString('en-US')+"<i>€)")
$('tr:nth-child(8) td:nth-child(4) div.level_text').html(price3+"<i><br><br>(Döviz Karşılığı: "+euro3.toLocaleString('en-US')+"<i>€)")
$('tr:nth-child(8) td:nth-child(5) div.level_text').html(price4+"<i><br><br>(Döviz Karşılığı: "+euro4.toLocaleString('en-US')+"<i>€)")

}

</script>

<i><font size="2" color="">Not: Fiyatların Euro karşılıkları 9.23 kurundan hesaplanmaktadır.</font></i>

Here, as I stated above, we are trying to show to euro values of TRY prices in conjoint. And before this conjoint screener part, we are making participant to create their own vehicle in terms of engine type, horsepower transmission type etc. in the BYO section. The thing is, we added a condition that if participant chooses electric engine as engine type, we show up electric range options, which are not visible if participant chooses other engine types (such as diesel and petrol). So at that point, an additional row comes up (Electric range) and messes up the first part of the code stated above. So, we added the second part to fix it and adjust column number conditionally. With this code, we can see the eur prices in preview mode but not in the test mode and also not from the test link. Strange right? Any ideas?
I haven't tried running any of your code, but just eyeballing it I see that you need to use "==" instead of "=" in your if / else if.

If you want to go a step further, we could remove the conditional code entirely.  What I usually do in situations like this - including in the Community Question Library item above - is add a dummy element like this to the price attribute label:

<input type="hidden" class="myPriceRow"/>


Then I can just look for that class in my JavaScript to automatically grab the row I'm interested in.  Check this out:

$('.myPriceRow').closest('tr').find('td:nth-child(2) div.level_text')


Looping could also help tidy up your script, but one step at a time.

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.
...