Treating Special Characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Hill

    Treating Special Characters

    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","Sourc e 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.c reateElement("T D");

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

    // Appends each node following the structure.
    myTD.appendChil d(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

  • Martin Honnen

    #2
    Re: Treating Special Characters



    Michael Hill wrote:

    [color=blue]
    > 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","Sourc e 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.c reateElement("T D");
    >
    > //create the text node
    > myText=document .createTextNode (x);
    >
    > // Appends each node following the structure.
    > myTD.appendChil d(myText);
    >
    > What I see on the output is: "Body & Soap"
    >
    > What I should see is: "Body & Soap"[/color]

    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.
    --

    Martin Honnen


    Comment

    Working...