473,466 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
6 3817
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


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


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

"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
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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Smash | last post by:
i have this function: ------------------------------------------------------------ function isAlfaNumeric(vnos,space) { if (space==false) { validRegExp = /^{0,}$/; } else { validRegExp =...
0
by: WebHouse.Co | last post by:
Hi Sir I'm in my 2nd year in M.Sc. degree & I made a project about the powerful tools SQLXML 3.0 & updategram, so I made a list of programs which r they so similar to the example that using...
2
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview....
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: annivanova | last post by:
Hi, I saw posts in Dependent listboxes on access forms, which problem is very similar to my. I’m working over to create an MS Access application. I used in my project given code : Code:...
17
by: Navodit | last post by:
So I have some code like: if (document.Insurance.State.selectedIndex == 1) { ifIll(); } else if (document.Insurance.State.selectedIndex == 2) { elseKan(); }
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
2
coolv
by: coolv | last post by:
Hello I have problem in my page that the dropdown box is not displaying data according to selection of first dropdown.Please help me. Below is my code. thanks.............. <?php ...
2
by: swethak | last post by:
Hi, i am getting the problem when i used the onclick event in option tag.It is working fine in mozilla .But it is not working IE. Here is my code <script>
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.