Prototype v1.6.0.2 - Changing $ Dollar Currency to £ Sterling

46 views
Skip to first unread message

Edward Nygma

unread,
Apr 18, 2012, 9:35:26 AM4/18/12
to Prototype & script.aculo.us
Hello,

I have written a script in Prototype version 1.6.0.2 and have written
the following function. I am currently unable to achieve the desired
British Pound Sterling (£) currency symbol as opposed to the United
States Dollar ($).

May I have any suggestions as to how I can achieve this? My code has
been supplied below:




sub_total: function() {
var In = this
return $$('.item').inject(0, function(sum, row) {
var quantity = Number($F('Item' + row.id + 'Quantity'))
var price = Number($F('Item' + row.id + 'Price'))
var line_total = quantity * price
$('Item' + row.id + 'Quantity').value = In.to_money(quantity)
$('Item' + row.id + 'Price').value = In.to_money(price)
$('Item' + row.id + 'Total').update('$' +
In.to_money(line_total))
return sum + line_total
})
},

tax: function() {
var tax_rate = Number($F('InvoiceTaxRate')) // passes in an item
var taxable_amount = this.sub_total()
tax_total = Math.round((tax_rate * 0.01 * taxable_amount) *
1000) / 1000
return Math.round(tax_total * 100) / 100
},

total: function() {
return this.sub_total() + this.tax()
},

refresh: function() {
$('subtotal').update('$' + this.to_money(this.sub_total()))
$('total').update('$' + this.to_money(this.total()))
$('tax').update('$' + this.to_money(this.tax()))
this.validate();
}


});

Victor

unread,
Apr 19, 2012, 4:49:05 AM4/19/12
to prototype-s...@googlegroups.com
It is very doubtful to me that someone was able to write OOP code (e.g. return this.sub_total() + this.tax()), CSS selectors, properly use inject() in calculations but wasn't able to replace character in string literals.

Edward Nygma

unread,
Apr 19, 2012, 9:09:37 AM4/19/12
to Prototype & script.aculo.us
Is the error blindingly obvious? I'm having serious difficulties
replacing the character in string literals from the $ to the £
currency symbol.

Do I need to apply internationalisation and localisation functionality
or am I thinking about this in overcomplicated terms?

Edward Nygma

unread,
Apr 19, 2012, 9:13:18 AM4/19/12
to Prototype & script.aculo.us
I am having this symbol returned in the browser: �

When replacing the '$' in string literal to '£' in my code.

Edward Nygma

unread,
Apr 19, 2012, 9:15:05 AM4/19/12
to Prototype & script.aculo.us
� � - The symbol may not show up on this form when I post it. It is a
question Mark inside of a black diamond, unrecognised encoding I
assume.

Walter Lee Davis

unread,
Apr 19, 2012, 9:16:56 AM4/19/12
to prototype-s...@googlegroups.com
Is your code saved in UTF-8, and does your server send it under a Content-type header including that charset? yourString.gsub('$','£') should just work as long as your surrounding page is Unicode.

Walter

On Apr 19, 2012, at 9:13 AM, Edward Nygma wrote:

> I am having this symbol returned in the browser: �
>
> When replacing the '$' in string literal to '£' in my code.
>

> --
> You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group.
> To post to this group, send email to prototype-s...@googlegroups.com.
> To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
>

Edward Nygma

unread,
Apr 19, 2012, 9:25:03 AM4/19/12
to Prototype & script.aculo.us
I am developing in CakePHP and this is my header file that every page
uses. Do I need to revise my Content-type header?

Here is my header.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> <?php echo $title_for_layout; ?></title>
<?php if(isset($javascript)) echo $javascript->link(array('prototype',
'invoice')) ?>
<?php echo $html->css('application');?>
</head>

Edward Nygma

unread,
Apr 19, 2012, 9:45:56 AM4/19/12
to Prototype & script.aculo.us
My server is running locally on XAMPP and as far as I know is sending
it to my browser in UTF-8

When I view source as shown below UTF-8 encoding is sent to the
browser, however the £ symbol is still unrecognised.

Walter Lee Davis

unread,
Apr 19, 2012, 10:31:01 AM4/19/12
to prototype-s...@googlegroups.com

On Apr 19, 2012, at 9:45 AM, Edward Nygma wrote:

> My server is running locally on XAMPP and as far as I know is sending
> it to my browser in UTF-8

This is a potential problem source. Can you locate the php.ini file, and see precisely what value is set for the default_charset value? By default, this is set to empty, and that kicks the can up to Apache, which may not be configured to send Unicode by default.

>
> When I view source as shown below UTF-8 encoding is sent to the
> browser, however the £ symbol is still unrecognised.

What do you see if you use a static HTML file, viewed locally (file / open), with the charset mime tag set to utf-8 -- instead of viewing from your server?

Walter

>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
> www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>

Walter Lee Davis

unread,
Apr 19, 2012, 11:17:06 AM4/19/12
to prototype-s...@googlegroups.com
Check again to be certain that the text editor you are using saves in UTF-8 (No BOM) format. You may be sending the right header, but the wrong code-points. It may look fine in your editor because of silent charset munging. (Attached is not using your actual calculation code, just a simple string replacement. It works here, and from my server http://scripty.walterdavisstudio.com/price.html )

Walter

price.html

Victor

unread,
Apr 19, 2012, 11:48:07 AM4/19/12
to prototype-s...@googlegroups.com
Try to use unicode "\u00a3" instead of single character "£"

Brian Marquis

unread,
Apr 19, 2012, 12:47:35 PM4/19/12
to prototype-s...@googlegroups.com
 
I've encountered similar issues trying to resolve accented characters for spanish translations of my web sites. The quickest way I've found to resolve character set issues was to replace character codes with the html entity for that symbol. Having said that, try using &pound; instead.

 

 

Brian Marquis

unread,
Apr 19, 2012, 12:51:22 PM4/19/12
to prototype-s...@googlegroups.com
Trying using the html entity instead: &pound;
 
Message has been deleted
Message has been deleted
Message has been deleted

Edward Nygma

unread,
Apr 20, 2012, 5:31:02 AM4/20/12
to Prototype & script.aculo.us
Thank you for all of your inputs,

Walter I have been using Microsoft Expression Web and discovered
automatic BOM applied to the JS file and have resaved without BOM and
ensured UTF-8 encoding.

Brian your suggestion of the html entity worked.

My application is now working as desired, may I again thank you for
all of your thoughts that helped me to fix this issue.

Reply all
Reply to author
Forward
0 new messages