Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accents in Javascript 1

Status
Not open for further replies.

ajarantes

Programmer
Jan 29, 2003
8
If I use this command:

==> w i n d o w . d o c u m e n t . w r i t e l n ( " A t e n & c c e d i l ; & a t i l d e ; o " ) ;

the result is the expected, i.e., A t e n ç ã o

on the other hand, if I use this other command:

==> w i n d o w . a l e r t ( " A t e n & c c e d i l ; & a t i l d e ; o " ) ;

it gives me back exactly what I wrote. It doesn't seem to interpret the & c c e d i l ; nor the & a t i l d e ;. The result is A t e n & c c e d i l ; & a t i l d e ; o

Does anybody know why?

 
New to JavaScript, so I'm not familiar with the way you're doing it. However, using an escape sequence including the hex #s, you can get the result you're looking for. Try this:

window.alert("Aten\xE7\xE3o");

Good luck.
 
very nice melt7. star for that one.

reasoning behind the alert and write working differently is the alert and other dialogs do not support the character entities that the write method does. _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
 
very deserving, that was a great tip

also sense I'm here, just a note that if you use the character entities outside the script tags it will pick them up in a dialog box. as in a event like onClik='javascript:alert("Atenção");'
only when the you are with in the script tags does the character entities get interpruted a different way. _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
 
and of course I forgot the spaces in there, I think you all got the idea. [lol] _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
 
It works perfectly. Thank you very much...
 
my two cents: i believe the reason for this behavior is this: in both cases javascript is outputting the same data "A t e n & c c e d i l ; & a t i l d e ; o", however in the case of document.writeln(), the results are displayed through the browser which knows to interpret the entities. The alert box is more of a system control that doesn't interpret HTML entities.

=========================================================
if (!succeed) try();
-jeff
 
So, Does anybody have any idea where I can get a list of these 'hex #s'?
"Why is it always the quiet ones?"

Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
AIM & MSN: robacarp
 
Search on google for "Latin-1 character set", lots of pages listed there.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top