469,923 Members | 1,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Escaping quotes for innerHTML in Mozilla

Hello,

I want to dynamically create a table cell with a textfield in it. The
value for the textfield can have quotes. e.g. ["test" ]

I have this snippet of javascript code:

var td = document.createElement('td');
var cellMarkup = '<input value="&quot;test&quot;">';
td.innerHTML = cellMarkup;
alert("cellMarkup = " + cellMarkup + "\n" +
"td.innerHTML = " + td.innerHTML);

On Mozilla, the text in alert box shows up as:

cellMarkup = <input value="&quot;test&quot;"> <-- Good
td.innerHTML = <input value="test"> <-- Bad

In summary, I am trying to escape the quotes in "test". The escaped
quotes disappear, however, when I set the markup in innerHTML. The
string "test works correctly though. And on IE the escaping the
quotes works all the time.

Does anyone have hints on how to get this to work on Mozilla? I've
already tried escaping with \" and that doesn't work either.

Thanks in advance,
-Ted
Jul 20 '05 #1
1 8243
Ted Weatherly wrote:
Hello,

I want to dynamically create a table cell with a textfield in it. The
value for the textfield can have quotes. e.g. ["test" ]

I have this snippet of javascript code:

var td = document.createElement('td');
var cellMarkup = '<input value="&quot;test&quot;">';
td.innerHTML = cellMarkup;
alert("cellMarkup = " + cellMarkup + "\n" +
"td.innerHTML = " + td.innerHTML);

On Mozilla, the text in alert box shows up as:

cellMarkup = <input value="&quot;test&quot;"> <-- Good
td.innerHTML = <input value="test"> <-- Bad

In summary, I am trying to escape the quotes in "test". The escaped
quotes disappear, however, when I set the markup in innerHTML. The
string "test works correctly though. And on IE the escaping the
quotes works all the time.

Does anyone have hints on how to get this to work on Mozilla? I've
already tried escaping with \" and that doesn't work either.

Thanks in advance,
-Ted


A work around would be to change the " to a ' and then escape it using \
so it comes out as \'. Should work

Gary
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Dave Moore | last post: by
4 posts views Thread by sankofa | last post: by
4 posts views Thread by Stefan Richter | last post: by
5 posts views Thread by Lucian Sandor | last post: by
7 posts views Thread by duwayne | last post: by
8 posts views Thread by Clément | last post: by
3 posts views Thread by Taras_96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.