Shadar
09-01-2006, 02:20 PM
I am pulling my hair out and I think this is something to do with the DOM, if not please point me at the correct forum to post in.
I have a PHP script that generates a table which can be sorted using Javascript.
When I echo out the php variable into the html I get the correct Japanese characters, when I put it into an array and build the table using the DOM I don't.
Here are some code snippets:
Data:
var jsData = new Array();
jsData[0] = {title:"Another Title", time:"10 分"};
Generating the table cell:
td = document.createElement("td");
txt = document.createTextNode(jsData[i].time);
td.appendChild(txt);
tr.appendChild(td);
Now for some reason instead of the character (分) it outputs the code raw 分.
One more piece of information that may be helpful, when I view source in Firefox it nicely highlights the the numerical part of the code red outside the javascript where it is displayed correctly but doesn't highlight it where it is output raw or inside the script.
Questions:
Do I need to encode multi-byte characters in some way for them to work in Javascript arrays?
Do I have to tell createTextNode() that I am giving it something that may contain multi-byte characters?
Any help muchly appreciated,
Shadar
I have a PHP script that generates a table which can be sorted using Javascript.
When I echo out the php variable into the html I get the correct Japanese characters, when I put it into an array and build the table using the DOM I don't.
Here are some code snippets:
Data:
var jsData = new Array();
jsData[0] = {title:"Another Title", time:"10 分"};
Generating the table cell:
td = document.createElement("td");
txt = document.createTextNode(jsData[i].time);
td.appendChild(txt);
tr.appendChild(td);
Now for some reason instead of the character (分) it outputs the code raw 分.
One more piece of information that may be helpful, when I view source in Firefox it nicely highlights the the numerical part of the code red outside the javascript where it is displayed correctly but doesn't highlight it where it is output raw or inside the script.
Questions:
Do I need to encode multi-byte characters in some way for them to work in Javascript arrays?
Do I have to tell createTextNode() that I am giving it something that may contain multi-byte characters?
Any help muchly appreciated,
Shadar