473,802 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="soeskende5s let" style="position : absolute; right: 70px;
cursor:hand; text-decoration:unde rline;" onClick="soeske ndeSlet('5','An ders
Nielsen')">slet </span>

Therefore I have inserted the following line into a function:
document.getEle mentById("soesk endecelle").inn erHTML = "<span
id='soeskende5s let' style='position : absolute; right: 70px; cursor:hand;
text-decoration:unde rline;' onClick="soeske ndeSlet('5','An ders
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.getEle mentById("soesk endecelle").inn erHTML = "<span
id='soeskende5s let' style='position : absolute; right: 70px; cursor:hand;
text-decoration:unde rline;' onClick=/"soeskendeSlet( '5','Anders
Nielsen')/">slet</span>"

document.getEle mentById("soesk endecelle").inn erHTML = "<span
id='soeskende5s let' style='position : absolute; right: 70px; cursor:hand;
text-decoration:unde rline;' onClick=soesken deSlet('5','And ers
Nielsen')>slet</span>"

document.getEle mentById("soesk endecelle").inn erHTML = "<span
id='soeskende5s let' style='position : absolute; right: 70px; cursor:hand;
text-decoration:unde rline;' onClick='soeske ndeSlet('5','An ders
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 1820


Anders Nielsen wrote:

my problem looks like this:

I would like to, dynamically, insert the following html into a table cell:
<span id="soeskende5s let" style="position : absolute; right: 70px;
cursor:hand; text-decoration:unde rline;" onClick="soeske ndeSlet('5','An ders
Nielsen')">slet </span>


cellElement.inn erHTML = '<span id="soeskende5s let" style="position :
absolute; right: 70px; cursor:hand; text-decoration:unde rline;"
onClick="soeske ndeSlet(\'5\',\ 'Anders Nielsen\')">sle t</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*******@yaho o.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.innerHTM L to the following:
<p>John said, "I went to Mary's house."</p>
Do it this way:
myText.innerHTM L='<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.innerHTM L=x;
....Jim Lee, Dallas, TX...

"Anders Nielsen" <anchSNABELAema il.dk> wrote in message
news:42******** *************@d read11.news.tel e.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="soeskende5s let" style="position : absolute; right: 70px;
cursor:hand; text-decoration:unde rline;" onClick="soeske ndeSlet('5','An ders Nielsen')">slet </span>

Therefore I have inserted the following line into a function:
document.getEle mentById("soesk endecelle").inn erHTML = "<span
id='soeskende5s let' style='position : absolute; right: 70px; cursor:hand;
text-decoration:unde rline;' onClick="soeske ndeSlet('5','An ders
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.getEle mentById("soesk endecelle").inn erHTML = "<span
id='soeskende5s let' style='position : absolute; right: 70px; cursor:hand;
text-decoration:unde rline;' onClick=/"soeskendeSlet( '5','Anders
Nielsen')/">slet</span>"

document.getEle mentById("soesk endecelle").inn erHTML = "<span
id='soeskende5s let' style='position : absolute; right: 70px; cursor:hand;
text-decoration:unde rline;' onClick=soesken deSlet('5','And ers
Nielsen')>slet</span>"

document.getEle mentById("soesk endecelle").inn erHTML = "<span
id='soeskende5s let' style='position : absolute; right: 70px; cursor:hand;
text-decoration:unde rline;' onClick='soeske ndeSlet('5','An ders
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.innerHTM L to the following:
<p>John said, "I went to Mary's house."</p>
Do it this way:
myText.innerHTM L='<p>John said, "I went to Mary' + "'" + 's house."</p>';
No, you do it this way:

myText.innerHTM L='<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.javas cript 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
9803
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 ---------------------------------------------------------------------------- -------------------------------------------- Here's how the site works: You should press a button in the rollover area in order to load a source file on an Iframe, this Iframe is actually hidden working as a Buffer. The body of this loaded Iframe is...
1
9108
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 = document.createElement('td'); var cellMarkup = '<input value="&quot;test&quot;">'; td.innerHTML = cellMarkup;
4
2025
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 helpful. The source code is at the bottom of the post. Thankyou very much,
6
10158
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 have the function update the target ID with the URL. There is a bit more to it then that, but that is the basics. my difficulty comes when I try to assign a variable to: "document.getElementById('-> var gose here <-').innerHTML"
2
2963
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 successfully applies the formatting from the datalist ( ie the dl's <ItemStyle> properties ), but ignores any of the formatting 'hard coded' into the SQL data being returned, eg things like <div class="newpara">. This in-table formatting appears OK on the...
7
2412
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 of the questions, that form is hidden and the next is displayed. Also, as the user answers each question a "count" variable is updated based on their response. I would like the question to show up on the left side and the answer to show up in the...
7
38027
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 using innerHTML. Now, I've researched this problem on the web, and found many references to it, but none of them quite addressed my specific situation, and since my experience with JavaScript is limited, I was not able to adapt the solutions I...
6
4388
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 browser, I found the "source" is still the old content the same as before I replaced them with the "innerhtml". This causes some problem with my other dynamic links based on the content of the page as they pull the old content instead of the new...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.