On Jun 4, 11:18 am, Martin Honnen <mahotr...@yaho o.dewrote:
Dan Andrews wrote:
option = document.create Element("OPTION ");
// option.appendCh ild(document.cr eateTextNode("& eacute; - example"));
JavaScript supports string literals with Unicode characters so you can
simply use that character in a string literal e.g.
option.appendCh ild(document.cr eateTextNode('é - example'));
Then there is String.fromChar Code e.g.
document.create TextNode(String .fromCharCode(2 33) + ' - example')
and there are Unicode escape sequences
document.create TextNode('\u00E 9 - example')
--
Martin Honnen
http://JavaScript.FAQTs.com/
Thanks this is very good to know, however, I don't quite have
literals. I have both entity references and some unicode ("Anhui
\u5b89\u5fbd", "Ñuble", ...) in my real situation. The text is
actually coming from a database via an XMLHttpRequest object and the
responseText. I believe these literals are interpreted a bit
differently when they are hard coded as in your '\u00E9 - example'
versus when they are sent across the wire in an XMLHttpRequest, or is
there a way to specify the characterset in an XMLHttpRequest. The
innerHTML is working well if I convert \u5b89 to &#xu5b89;, but I
still would like to avoid innerHTML.
[snip]
request = new XMLHttpRequest( );
request.open("G ET", "countries?fn=r egions&id=" +
countryTypeIdSe lected, true);
request.onready statechange = function() {
var i;
var array;
var option;
var select = document.getEle mentById("regio n");
var cdata;
if (request.readyS tate == 4) {
array = request.respons eText.split(',' );
if(array.length 1){
for(i=0; i < array.length - 1; i = i + 2){
option =
document.create Element("OPTION ");
option.setAttri bute("value", "" +
array[i]);
if(countryTypeI dSelected && countryTypeIdSe lected
=== array[i]){
option.setAttri bute("selected" , "selected") ;
}
//option.appendCh ild(document.cr eateTextNode("" +
array[i+1]));
option.innerHTM L = "" + array[i+1];
select.appendCh ild(option);
select.disabled = false;
}
}
[snip]