473,395 Members | 1,495 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,395 software developers and data experts.

Problems with innerHTML and "

Hi :-)

I'm currently working with innerHTML , but it is giving me some problems
with " and '.

Basically (there is also some ASP involved), my problem looks like this:

I would like to, dynamically, insert the following html into a table cell:
<span id="soeskende5slet" style="position: absolute; right: 70px;
cursor:hand; text-decoration:underline;" onClick="soeskendeSlet('5','Anders
Nielsen')">slet</span>

Therefore I have inserted the following line into a function:
document.getElementById("soeskendecelle").innerHTM L = "<span
id='soeskende5slet' style='position: absolute; right: 70px; cursor:hand;
text-decoration:underline;' onClick="soeskendeSlet('5','Anders
Nielsen')">slet</span>"

Obviosly this will cause an error due to the use of " near onClick.

I have also tried with these different syntaxes:
document.getElementById("soeskendecelle").innerHTM L = "<span
id='soeskende5slet' style='position: absolute; right: 70px; cursor:hand;
text-decoration:underline;' onClick=/"soeskendeSlet('5','Anders
Nielsen')/">slet</span>"

document.getElementById("soeskendecelle").innerHTM L = "<span
id='soeskende5slet' style='position: absolute; right: 70px; cursor:hand;
text-decoration:underline;' onClick=soeskendeSlet('5','Anders
Nielsen')>slet</span>"

document.getElementById("soeskendecelle").innerHTM L = "<span
id='soeskende5slet' style='position: absolute; right: 70px; cursor:hand;
text-decoration:underline;' onClick='soeskendeSlet('5','Anders
Nielsen')'>slet</span>"

Each one produces an error!

Can anyone help me, please?

Any help is greatly appreciated :-)

Best regards
Anders

Jul 23 '05 #1
4 1787


Anders Nielsen wrote:

my problem looks like this:

I would like to, dynamically, insert the following html into a table cell:
<span id="soeskende5slet" style="position: absolute; right: 70px;
cursor:hand; text-decoration:underline;" onClick="soeskendeSlet('5','Anders
Nielsen')">slet</span>


cellElement.innerHTML = '<span id="soeskende5slet" style="position:
absolute; right: 70px; cursor:hand; text-decoration:underline;"
onClick="soeskendeSlet(\'5\',\'Anders Nielsen\')">slet</span>';

You can use
'"'
without escaping and you can use
"'"
without escaping too but if you want to use a single quote inside a
single quote delimited string literal then you need to escape it
'\''
same for
"\""

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

"Martin Honnen" <ma*******@yahoo.de> wrote in message news:427cacc8$0$7521
You can use
'"'
without escaping and you can use
"'"
without escaping too but if you want to use a single quote inside a
single quote delimited string literal then you need to escape it
'\''
same for
"\""


Thanks Martin - You're the man! :-)
Jul 23 '05 #3
End one string, use the plus (+) sign and concatenate another string using
different outer quotes.
Example: I want to set myText.innerHTML to the following:
<p>John said, "I went to Mary's house."</p>
Do it this way:
myText.innerHTML='<p>John said, "I went to Mary' + "'" + 's house."</p>';

And sometimes -- especially for longer strings -- it is more readable to set
a variable with multiple instructions, like this:
var x=""
x += '<p>John said, I went to Mary';
x += "'";
x += 's house."</p>';
myText.innerHTML=x;
....Jim Lee, Dallas, TX...

"Anders Nielsen" <anchSNABELAemail.dk> wrote in message
news:42*********************@dread11.news.tele.dk. ..
Hi :-)

I'm currently working with innerHTML , but it is giving me some problems
with " and '.

Basically (there is also some ASP involved), my problem looks like this:

I would like to, dynamically, insert the following html into a table cell:
<span id="soeskende5slet" style="position: absolute; right: 70px;
cursor:hand; text-decoration:underline;" onClick="soeskendeSlet('5','Anders Nielsen')">slet</span>

Therefore I have inserted the following line into a function:
document.getElementById("soeskendecelle").innerHTM L = "<span
id='soeskende5slet' style='position: absolute; right: 70px; cursor:hand;
text-decoration:underline;' onClick="soeskendeSlet('5','Anders
Nielsen')">slet</span>"

Obviosly this will cause an error due to the use of " near onClick.

I have also tried with these different syntaxes:
document.getElementById("soeskendecelle").innerHTM L = "<span
id='soeskende5slet' style='position: absolute; right: 70px; cursor:hand;
text-decoration:underline;' onClick=/"soeskendeSlet('5','Anders
Nielsen')/">slet</span>"

document.getElementById("soeskendecelle").innerHTM L = "<span
id='soeskende5slet' style='position: absolute; right: 70px; cursor:hand;
text-decoration:underline;' onClick=soeskendeSlet('5','Anders
Nielsen')>slet</span>"

document.getElementById("soeskendecelle").innerHTM L = "<span
id='soeskende5slet' style='position: absolute; right: 70px; cursor:hand;
text-decoration:underline;' onClick='soeskendeSlet('5','Anders
Nielsen')'>slet</span>"

Each one produces an error!

Can anyone help me, please?

Any help is greatly appreciated :-)

Best regards
Anders

Jul 23 '05 #4
Jimnbigd wrote:
End one string, use the plus (+) sign and concatenate another string using
different outer quotes.
NO.
Example: I want to set myText.innerHTML to the following:
<p>John said, "I went to Mary's house."</p>
Do it this way:
myText.innerHTML='<p>John said, "I went to Mary' + "'" + 's house."</p>';
No, you do it this way:

myText.innerHTML='<p>John said, "I went to Mary\'s house."</p>'

And that is assuming the myText is a proper reference to an element that
has an innerHTML property.
And sometimes -- especially for longer strings -- it is more readable to set
a variable with multiple instructions, like this:


Maybe more readable but more error-prone and less-efficient.

And please read this groups FAQ with regards to, among other things,
top-posting.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Javier | last post by:
Hello, I'm very new in this forum and as I have the following problem, the website is in http://new.vanara.com ----------------------------------------------------------------------------...
1
by: Ted Weatherly | last post by:
Hello, I want to dynamically create a table cell with a textfield in it. The value for the textfield can have quotes. e.g. I have this snippet of javascript code: var td =...
4
by: B. Fletcher | last post by:
Hi, I'm having some trouble with javascript code of mine: When the script runs, I vget an error in line 119: Number Expected. I'm not sure as to why this is happening. Any advice would be...
6
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and...
2
by: yer darn tootin | last post by:
Here's the scenario: I have a javascript function taking the contents of a datalist ( content from a SQL db ) and opening it in a new window to allow the user to print. The pop-up window...
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
7
by: John | last post by:
Hi Everyone, I'm having this extremely annoying problem with Internet Explorer 6, giving me an error message saying "unknown runtime error" whenever I try to alter the contents of a <divelement...
6
by: jluo | last post by:
I found a problem with my application when using "innerhtml" to replace the content from the server after making an ajax call. The display is perfectly correct, but when I use "view source" on the...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.