Fog Creek Software
Discussion Board

European formats in HTML input text boxes

To any i18n gurus:

I use an HTML form text box to allow the user to enter a price:

<input type="text" name="price">

Prices sometimes have a fractional amount such as "381.23"

In Europe people use commas instead of "dots" to separate the integer part from the fractional part as follows:


What do you suggest as a way for my javascript functions on the HTML page to effortlessly accept the European format or Anglo format depending on the user's locale? Without me having to do any creative conversion routines?


Herr Herr
Friday, June 25, 2004

Two separate boxes?

Friday, June 25, 2004

Why not just accept both?

Thom Lawrence
Friday, June 25, 2004

The UK (nominally part of Europe :) it's the same as in the US.

Here in mainland Europe they use the "." to seperate the thousands. Basically it's the other way round. But whether not users will use them is unknown.

Friday, June 25, 2004

You need a locale lookup table which has the locale differences and for currency boxes you need as a minimum to field the decimal separator so that users recognise it.

There are other locale differences that you'd do well to acknowledge as well, such as date formats.

Simon Lucy
Friday, June 25, 2004

(I am the OP)


I know I can do it programmatically. Let me state a question another way: Is there a simple JavaScript setting that says _on the client-side_ use continental Europe number formats instead of Anglo formats for display and input.

So when I copy a float into a form text box, instead of looking like this:


it looks like this:


And as well, I could then use JavaScript's auto parsing of numbers when using the number for calculations.

No, I can't do both. In Germany "1.234" means one thousand, two hundred and thirty four, while in the Anglo world it means one point two three four. The locale has to be taken into account.

I really don't want to have write JavaScript code to check locales and generate appropriate output when I already have access to libraries in my back Java code to do that stuff.

Any ideas?


Herr Herr
Friday, June 25, 2004

Would the HTTP client header "Accept-Language" help you? You could use the language code to determine how to format the values.

Duncan Smart
Friday, June 25, 2004

No, he doesn't want to format the values himself.

I would expose some of those internal Java functions to the HTML page so that Javascript can access them Herr Herr, because you won't find any standard browser feature to help you.

Friday, June 25, 2004

I faced a similar situation in an app that I wrote.  I ended up writing Java code that would take the language preferences of the client and return an object to do all of the localization.  It did both string substitutions and formatting.  The only time it got really bad was when the Javascript on the page was locale-dependent (smart date picker).
Since it should be a common problem, I may have reinvented the wheel, but I didn't find anything that did what I wanted.

Friday, June 25, 2004

*  Recent Topics

*  Fog Creek Home