an******@gmail.com wrote:
Greetings!
I'm using a dropdown to set the value of a textarea to some text pulled
from a database.
This text is something like this:
单元
When I use a simple "document.write", it displays the characters
perfectly. When I set the textarea value to the same text, it shows
the "单元" instead.
Is there some sort of Javascript encoding I'm supposed to set?
Based on a Mike Winter post[1], the following should do the trick:
function replaceCharCodes(str)
{
return str.replace(/&#(\d+);/g,
function() {
return String.fromCharCode(arguments[1]);
});
}
e.g.
alert(charCodeToString('Üfooá bar Õ'));
May not be supported by some browsers, particularly older ones.
1.
<URL:http://groups.google.co.uk/group/comp.lang.javascript/browse_frm/thread/2798ad11319d23a4/76b3e80aa2334212?q=textarea+HTML+entities&rnum=2#7 6b3e80aa2334212>
--
Rob