473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 8988
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave Moore | last post by:
Hi All, Can anybody point me to a FAQ or similar that describes what all this stuff is about please?. I'm interfacing with a MySQL database if that's relavent. I've read a couple of books which...
4
by: sankofa | last post by:
hi, i can't seem to be able to escape my single quote properly... is it even possible in javascript? this is a portion of my code.. var DLEWIS="Pastor Lewis"; .... Sermon is a yser-defined...
4
by: Stefan Richter | last post by:
How do I encode double quotes and quotes and in a string in VB.NET? It also has to be save for MS SQL Server... Stefan
5
by: Lucian Sandor | last post by:
Hello everyone, While I'm a newbie here, I a not new to google, so please don't send me back, it would be useless. First of all I have to specify I am working on a Blogger.com template, therefore...
7
by: duwayne | last post by:
I have a problem of escaping quotes in javascript. Ex: onclick='alert( "Mister O'Hara" )' onclick='alert( "Mister O\'Hara" )' both gives me an error. How would I escape this?
8
by: Clément | last post by:
Hi! I am currently developping a user interface with Ajax/C#/.net. And I am facing a problem with Mozilla, and Firefox. I use the function innerHTML to load a Web UserControl into a div, this...
3
by: Taras_96 | last post by:
Hi everyone, I'm having a bit of trouble understanding the purpose of escaping nulls, and the use of addcslashes. Firstly, the manual states that: "Strictly speaking, MySQL requires only...
1
by: Jonny B | last post by:
I've been working on an xsl transfomation on the clientside using JavaScript for a few days now and have been pulling my hair out because Mozzilla doesnt support output escaping but Internet Explorer...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.