By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,928 Members | 1,587 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,928 IT Pros & Developers. It's quick & easy.

problem display foreign characters in javascript country/region dropdown ...

P: n/a
Initially the form is loaded using ASP and HTML and the ü codes
display the characters correctly. I have the values stored in a
javascript array so that I can more easily and dynamically change the
state/region dropdown when the country changes. However, when my
javascript code tries to add the new option and print out new region
the literal value such as "Würrtemberg" is displayed instead of
the special character.

Can this be done in javascript?
(I saw a previous old question about this, but no reply.)

Thanks.
Melissa Mussitsch

Oct 16 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Initially the form is loaded using ASP and HTML and the ü codes
display the characters correctly. I have the values stored in a
javascript array so that I can more easily and dynamically change the
state/region dropdown when the country changes. However, when my
javascript code tries to add the new option and print out new region
the literal value such as "Würrtemberg" is displayed instead of
the special character.
Hi Melissa,

the HTML entities like ü are not properly evaluated by the JavaScript
interpreter when assigning them as values of option items. This may be
browser dependent.
You can try to encode the values as hex unicode codepoints. In the example,
this would be W\u00FCrrtemberg. (By the way, the correct spelling is
"Württemberg" with one r and two t. It's close to where I live ;-)
It should be fairly easy to parse the contents of your array, detect the
entities and replace them with the equivalent unicode hex code. Or simply
hard-code them, doesn't matter as long as they are not loaded from a DB.

Hope this helps,

Leo
Oct 16 '06 #2

P: n/a


On Oct 16, 4:12 pm, "Leo Meyer" <leomeyer_LIKES_NO_S...@gmx.dewrote:
Initially the form is loaded using ASP and HTML and the ü codes
display the characters correctly. I have the values stored in a
javascript array so that I can more easily and dynamically change the
state/region dropdown when the country changes. However, when my
javascript code tries to add the new option and print out new region
the literal value such as "Würrtemberg" is displayed instead of
the special character.Hi Melissa,

the HTML entities like ü are not properly evaluated by the JavaScript
interpreter when assigning them as values of option items. This may be
browser dependent.
You can try to encode the values as hex unicode codepoints. In the example,
this would be W\u00FCrrtemberg. (By the way, the correct spelling is
"Württemberg" with one r and two t. It's close to where I live ;-)
It should be fairly easy to parse the contents of your array, detect the
entities and replace them with the equivalent unicode hex code. Or simply
hard-code them, doesn't matter as long as they are not loaded from a DB.

Hope this helps,

Leo
Leo,

Thank you so much for your response. I think this gets me closer and
at least I know I'm not losing my mind!
However, do you know of a formula to convert the HTML entity to the
unicode hex code? I didn't find anything in my search and know in my
instance that the number of characters I need to convert is too many to
hard-code. I was testing with the JavaScript charCodeAt function but
don't think this is getting me what I need and I don't fully understand
unicode versus unicode hex versus ascii and then html entities, etc.
It gets very confusing to me.

Thanks.
Melissa

Oct 17 '06 #3

P: n/a


On Oct 16, 10:46 pm, "Melissa" <melissa.mussit...@ansys.comwrote:
On Oct 16, 4:12 pm, "Leo Meyer" <leomeyer_LIKES_NO_S...@gmx.dewrote:


Initially the form is loaded using ASP and HTML and the ü codes
display the characters correctly. I have the values stored in a
javascript array so that I can more easily and dynamically change the
state/region dropdown when the country changes. However, when my
javascript code tries to add the new option and print out new region
the literal value such as "Würrtemberg" is displayed instead of
the special character.Hi Melissa,
the HTML entities like ü are not properly evaluated by the JavaScript
interpreter when assigning them as values of option items. This may be
browser dependent.
You can try to encode the values as hex unicode codepoints. In the example,
this would be W\u00FCrrtemberg. (By the way, the correct spelling is
"Württemberg" with one r and two t. It's close to where I live ;-)
It should be fairly easy to parse the contents of your array, detect the
entities and replace them with the equivalent unicode hex code. Or simply
hard-code them, doesn't matter as long as they are not loaded from a DB.
Hope this helps,
LeoLeo,

Thank you so much for your response. I think this gets me closer and
at least I know I'm not losing my mind!
However, do you know of a formula to convert the HTML entity to the
unicode hex code? I didn't find anything in my search and know in my
instance that the number of characters I need to convert is too many to
hard-code. I was testing with the JavaScript charCodeAt function but
don't think this is getting me what I need and I don't fully understand
unicode versus unicode hex versus ascii and then html entities, etc.
It gets very confusing to me.

Thanks.
Melissa- Hide quoted text -- Show quoted text -

Leo - actually I think I've realized that I need to convert my html
entity decimal value to hex. parseInt is not working the way I want it
to at the moment, but I'll work through that. I think I'm just tired!

Thanks.
Melissa

Oct 17 '06 #4

P: n/a

"Melissa" <me***************@ansys.comschrieb im Newsbeitrag
news:11*********************@m73g2000cwd.googlegro ups.com...
Thank you so much for your response. I think this gets me closer and
at least I know I'm not losing my mind!
Take it easy ;-)
>Leo - actually I think I've realized that I need to convert my html
entity decimal value to hex. parseInt is not working the way I want it
to at the moment, but I'll work through that. I think I'm just tired!
It's fairly simple. You could define a function that takes a string.
Get the position of an HTML entity ("&#").
If found (position -1), append characters up to this position to the
result variable.
Collect characters up to the next ";" or the end of the string.
Check that the characters are in fact a number.
Convert the number to hex, prefix with 0's if necessary. Append to the
output.
Remove chars from the input string up to the end of the entity.
Repeat until no more entities can be found.
Return the result string.

Such type of string parsing is fairly common practice. Unfortunately, it is
rarely taught. If you can't get it to work, post your code here, and we'll
se what we can do ;-)

Leo
Oct 17 '06 #5

P: n/a
Melissa wrote:
Initially the form is loaded using ASP and HTML and the ü codes
display the characters correctly. I have the values stored in a
javascript array so that I can more easily and dynamically change the
state/region dropdown when the country changes. However, when my
javascript code tries to add the new option and print out new region
the literal value such as "Würrtemberg" is displayed instead of
the special character.
alert ('Schöne Mädchen in Würtemburg!'
.replace(/(&)(#)(\d{1,})(;)/g,
function (tot,amp,cr,cp,sem) {
return String.fromCharCode(cp)
}
)
)

--
Bart

Oct 17 '06 #6

P: n/a


On Oct 17, 4:56 am, "Bart Van der Donck" <b...@nijlen.comwrote:
Melissa wrote:
Initially the form is loaded using ASP and HTML and the ü codes
display the characters correctly. I have the values stored in a
javascript array so that I can more easily and dynamically change the
state/region dropdown when the country changes. However, when my
javascript code tries to add the new option and print out new region
the literal value such as "Würrtemberg" is displayed instead of
the special character. alert ('Schöne Mädchen in Würtemburg!'
.replace(/(&)(#)(\d{1,})(;)/g,
function (tot,amp,cr,cp,sem) {
return String.fromCharCode(cp)
}
)
)

--
Bart
Thank you so much! This worked like a charm!!

Melissa

Oct 17 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.