Currency variable equals dollar sign, how do I print it? Jquery issue

Go To StackoverFlow.com

1

Without getting in to too much detail and without people getting too hung up on it.

The variable backup currency for this case is equal to $.

I'm using Chrome V8 in the section where the variable is passed to the HTML so I can use basic Javascript functions there but NO jQuery.

I'm passing a variable into the HTML via Template Toolkit like so:

var backupcurrency =   [% backupcurrency %];

Then in my JS:

var temp = backupcurrency + '';
console.log(typeof(temp));     
console.log(temp);

The output from this is that temp is a string but the value of temp is NOT '$' and instead for the value I get:

function (a,b){return new e.fn.init(a,b,h)}

I'm thinking maybe I can append to the string in the Chrome v8 step so that the dollar sign is escaped but I should be able to do that in the Jquery anyway.

Now I know this has to do with using Jquery but how do I literally print the $ - dollar sign AND deal with the case that the currency is equal to the dollar sign because if the variable is equal to £ or € I don't want those user's having issues?

Here is the code I want to use the variable in (again high level to avoid any confusion)

HTML:

<div id="upsell"></div>

JS:

var prod = "<div id='upselltext'><h6>Price: " + temp + backupvalue + "/year</h6></div>";

$('#upsell').append(prod);

backup value is a number, in this case '12.50'

EDIT:

Ok solved this by using JSON.stringify() on the variable before it was passed to the HTML

stash({backupcurrency: JSON.stringify(backupcurrency), backupvalue: backupvalue });

then the HTML remains the same but instead it is recognised as a character by jquery.

2012-04-05 17:03
by Davekilg
Have you tried to use the HTML number? For $ its $ - Sven Bieder 2012-04-05 17:37
ok that works but I had to write it as '&#36 ' meaning there's a space between the symbol and the value which isn't ideal but it works. But now how do I detect that the variable is the dollar sign in an IF statement and act accordingly - Davekilg 2012-04-05 17:44


0

I don't know anything about Template Toolkit, but if '&#36' (with space character) works, then try '&#36;' (with semicolon instead of space).

2012-04-05 17:51
by Peter
Ok that solves the spacing issue but I would then need to account for the case when the user's currency isn't dollars and how to deal with the variable in that case - Davekilg 2012-04-05 18:20
Template Toolkit builds on top of Perl, right? Then you might have more luck if you tag your question with Perl. I don't know any Perl, but I found this article, maybe it helps: http://www.perlmonks.org/?node_id=73112 - Peter 2012-04-06 10:39
HTML and JavaScript don't have any functions for regional formatting, so you will need to use a server-side language (like Perl) or create your own functions in JavaScript - Peter 2012-04-06 10:48
Ads