Click to See Complete Forum and Search --> : Special characters in DHTML
HEJ
May 22nd, 2002, 08:41 AM
Hi there !
I'm facing some strange behaviour in respect of displaying special characters like the 'umlauts' in German (ä, ö, ü etc.).
When I'm allocating such a character "statically" within a title attribute of an HTML control, everything works quite fine, e.g.:
<button name="back" style="border:0; background:transparent; cursor:hand" title="R&uuml;ck">
Hovering over this button at runtime unveils a proper "Rück" as the corresponding tooltip. Trying to alter the title contents dynamically via JScript however, doesn't translate the character code into the umlaut:
back.title = "Zur&uuml;ck";
The tooltip then contains "Zur&uuml;ck" instead of "Zurück".
Moreover, an "alert" out of JScript behaves likewise. "alert('Zur&uuml;ck');" activates an IE message box displaying "Zur&uuml;ck". Using the umlaut character directly in the source code ("alert('Zurück');") results in a partly "illegible" string, whereas "alert('&');" (non-masked ampersand) is shown as "&".
It looks like a browser bug !? I'm working with Internet Explorer 6 under WINNT 4.0 SP6a, both German language version.
I'd be grateful for any tips and suggestions. Thanks in advance.
Sam Hobbs
May 23rd, 2002, 06:35 PM
I'm not sure but I suspect that the text is not processed the same when it is used dynamically. I do not know if it is possible to use innerText and/or outerText properties but if it is possible then that is likely to work.
HEJ
May 28th, 2002, 02:21 AM
Obviously, this kind of problem (not only in respect of tooltips/title attribute but of text properties either) occurs when the IE installation is somehow inaccurate, as on other PCs with the same OS and browser (language) version and SP, it doesn't show up. Unfortunately, we couldn't figure out so far the exact reason for this strange behaviour of (non)processing special characters. The only "remedy" is likely to completely remove the IE and install it anew.
The "innerText" and "outerText" approach apparently doesn't solve the problem, but nontheless "Thanks" for the advice !
websmith99
October 14th, 2002, 05:07 PM
If you want to alter the contents dynamically and still have the ability to retain character entities, why not read the values from hidden form fields. Try out the sample code below, and press the "Change Text" button several times.
<html>
<head>
<script language="JavaScript">
function changeText(){
if (document.myform.back.value == document.myform.foo.value) {
document.myform.back.value = document.myform.foo2.value;
} else {
document.myform.back.value = document.myform.foo.value;
}
}
</script>
</head>
<body>
<form name="myform">
<input type="hidden" name="foo" value="R&uuml;ckseite" />
<input type="hidden" name="foo2" value="Gehen Sie" />
<input type="button" value="Change Text" onClick="changeText()" />
<button name="back" style="border:0; background:transparent; cursor:hand" title="Gehen Sie" />
</form>
</body>
</html>
Waldo2k2
October 14th, 2002, 06:42 PM
the only problem is that ie does special character interpretation when the page first opens, it won't evaluate it after that. So, do this:
<html>
<head>
<script language="JavaScript">
var someText="rück";
</script>
</head>
<body>
<script language="JavaScript">
document.writeln(someText);
</script>
<br>
same as rück
</body>
</html>
and yes i've tested this code, so whenever you need to write some special text dynamically, just load it in a variable in the head section, then you can use it later.
edit: the ü symbol in the above code should actually be the code for it, it parses it here and i'm not sure how to stop it, but otherwise the code works.
Sam Hobbs
October 14th, 2002, 07:21 PM
Originally posted by Waldo2k2
edit: the ü symbol in the above code should actually be the code for it, it parses it here and i'm not sure how to stop it, but otherwise the code works. I am not sure I understand what you want to do but one way to enter the "ü" character symbolically is to use "&uuml;" in this forum's software and in HTML.
websmith99
October 14th, 2002, 09:50 PM
Originally posted by waldo2k2 edit: the ü symbol in the above code should actually be the code for it, it parses it here and i'm not sure how to stop it, but otherwise the code works.
If you want to see the character ü then type in &uuml;
If you want to see &uuml; then type in the character entity for & and then type in uuml;
:cool:
Sam Hobbs
October 14th, 2002, 10:09 PM
Originally posted by websmith99
If you want to see &uuml; then type in the character entity for & and then type in uuml;To get "&" type "&amp;". So if you want "&uuml;" to be shown then type "&amp;uuml;".
websmith99
October 14th, 2002, 10:30 PM
Exactly what I was trying to convey- but Sam Hobbs put it more eloquently.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.