473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

setting textarea with special characters - won't render them


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?

Any help would be much appreciation.

Thanks,
Andy

Feb 14 '06 #1
2 2291
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
Feb 15 '06 #2
RobG wrote:
[...]

function replaceCharCodes(str)
{
return str.replace(/&#(\d+);/g,
function() {
return String.fromCharCode(arguments[1]);
});
}
e.g.

alert(charCodeToString('Üfooá bar Õ'));


Agghh...

alert(replaceCharCodes('Üfooá bar Õ'));

[...]
--
Rob
Feb 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: megha | last post by:
Hi all I am adding signature in textarea which is stored as text in database now if i add html tags to it and later retrieve it in textarea it shows all tags of html but not their function. How...
6
by: dan glenn | last post by:
hi. I'm having a problem using javasript to pass the value of a textarea (in a form) to a PHP script file. I want to code a 'preview' function into a guestbook entry page, using an HTML link...
2
by: ph0ngwh0ng | last post by:
Hi, I am building a simple form with a textarea and a submit button. The problem is that when there is more than about 1700-1800 characters in the textarea, the form won't submit(you can click...
4
by: J. VerSchave | last post by:
I am curious if there is a way to handle this... maybe with Javascript... Is there a way to set a TEXTAREA field so that the tab key on the user's keyboard will create a tab within the text...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
5
by: bwucke | last post by:
Is there any way to scroll textarea (to the bottom row) from Javascript in Opera? The textarea.scrollTop=textarea.scrollHeight+textarea.scrollTop; approach doesn't work, and there's so many...
2
by: Diilb | last post by:
I am using DOM to create an rss feed. The problem I am running into is "special characters" such as é è ç. If I try adding them to the XML as character data (CData), DOM chokes and throws out...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
14
by: EnjoyNews | last post by:
Hi I have a little probelm. I tranfer som data from input fields to a div so you can see how a profil will look as you type in your data. I just put this in my input field:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.