Pre-sales questions:
0800 848 8301
sales@kashflow.co.uk
CUSTOMER LOGIN
Username:
Password:
Benefits Faq Pricing Testimonials Register Security Add-Ons Resources Blog Forum About

Euro and other symbols getting mangled by AJAX/Javascript

On January 7th, 2009 by Duane Jackson

Another techie post, sorry!

We’ve just added multicurrency invoicing and quotes to our online accounting software. We’re supporting a wide range of currencies and wanted to also allow customers to enter their own.

So you select a currency, by name, from a drop down list. The software then sends out an AJAX request to our server, the server looks up the currency in our database and automatically fills in text boxes with the name, symbol and exchange rate of that currency. You can then overwrite the content of those boxes if you want to.

The Euro symbol and a few others caused us no end of problems. Writing document.getElementById(‘curSymbol’).value=’€’; works fine if the javascript code is on page or in a .js file referenced in the <head> area. However, when it’s sent over http using AJAX, it refused to work and just gave us weird symbols instead.

Google was no help whatsoever so we were left to our own devices.

The first work around we tried was to use javascripts native String.fromCharCode() function with the code for the symbol. This worked for some currency symbols, but not for the Euro.

We finally found a workaround that works for us, so I thought I’d detail it here in the hope it helps some other poor soul.

Our pages already have a .js file that’s included on virtually all of them. So we added a line to this to set up a variable: var symbol_euro=’€’;.

In our database with the currencies, we added a new field called “JSVariable”.

In our AJAX that gets the symbol, we also retrieve the contents of the JSVariable field.

If JSVariable is empty, then we proceed as normal. But if it does contain anything then instead of setting the text box to contain the raw symbol as per the database, we instead set it to the variable.

So instead of document.getElementById(‘curSymbol’).value=’€’;, our code would return document.getElementById(‘curSymbol’).value= symbol_euro; for the Euro symbol.

I hope that makes sense and I hope it saves someone some time.

[Post to Twitter]  [Post to Delicious]  [Post to Digg]  [Post to StumbleUpon] 

Tags: ,



Start your free trial




2 Responses to “Euro and other symbols getting mangled by AJAX/Javascript”

  1. Dobes Vandermeer Says:

    This really shouldn’t be an issue as long as you’ve set the right content-type and encoding (i.e. UTF-8) on your HTTP Response.

  2. Roger Jones Says:

    I had a similar issue with ajax response but resolved it by specifying the encoding type with a php header:

    (or )

Leave a Reply




Free Trial

Try KashFlow Bookkeeping
Software Free for 60 days



Fully functional
Free customer support
Create your own invoices
No credit card details taken
No obligation
Up and running in minutes



Start your free trial

KashFlow Partner Programme

SOAP Webservice

3 minute Tour

PayPal Certified Integration

HMRC Recognised Software for VAT Filing

Copyright © KashFlow Software Ltd 2008. All Rights Reserved.