Treating Special Characters

M

Michael Hill

I have a number of scripts that take special characters and convert them
to their ascii equivalents and them store them in the database.

However I am running into a problem that I have some of those fields are
loaded to an array and inserted into cells dynamically. As an example
the array would be:

var my_array = [ ["52","Source Data"], ["19","Body &
Soap"] ];

Then I have some javascript that creates the cell and inserts the value
into a cell text node like:

var x = my_array[1][1]; // this would be "Body & Soap"

//create the cell
myTD=document.createElement("TD");

//create the text node
myText=document.createTextNode(x);

// Appends each node following the structure.
myTD.appendChild(myText);

What I see on the output is: "Body & Soap"

What I should see is: "Body & Soap"

Anyone know how to get around this?

Mike
 
M

Martin Honnen

Michael Hill wrote:

However I am running into a problem that I have some of those fields are
loaded to an array and inserted into cells dynamically. As an example
the array would be:

var my_array = [ ["52","Source Data"], ["19","Body &
Soap"] ];

Then I have some javascript that creates the cell and inserts the value
into a cell text node like:

var x = my_array[1][1]; // this would be "Body & Soap"

//create the cell
myTD=document.createElement("TD");

//create the text node
myText=document.createTextNode(x);

// Appends each node following the structure.
myTD.appendChild(myText);

What I see on the output is: "Body & Soap"

What I should see is: "Body & Soap"

No, what you see is correct, you create a text node with the content
Body & Soap
and that is what you see.
If you want to have the ampersand literally then store
"Body & Soap"
in the JavaScript string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top