By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

using quotes in variables

P: n/a
Hi,

I use document.write in a HTML-document to display same information. Now I
have a problem displaying text that sometimes contains two kinds of quotes
simultanelisly. I don't know on beforehand if this is the situation. See
example:

## ---

<script language="JavaScript">
var a1; // text to display - variable between '
var a2; // text to display - variable between "

a1='This text (a1) contains the single (') and the double (") quote and is
placed between single quotes. How can I display this variable using
document.write?'

a2="This text (a2) contains the single (') and the double (") quote and is
placed between double quotes. How can I display this variable using
document.write?"

document.write(""+a1+" "+a2+"");
</script>

## ---

Is there possibly another character to use for placing around the text? Or
any other solution?

Thanks,

Sjoerd

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
my poor example, view in notepad or what ever, and hope the code goes
through the post intact..
<html><head><title></title>
</head><body text="#000000">
<script language="JavaScript"><!--
var a1='This text (a1) contains the single'
+'(\')and the double (") quote and is '
+'placed between single quotes.'
+'How can I display this variable using '
+'document.write?<br><br>'
var a2="This text (a2) contains the "
+"single (') and the double (\") "
+"quote and is placed between "
+"double quotes. How can I display "
+"this variable using "
+"document.write?<br><br>"
var b1='document.write(\'"+a1"\"+a2+"\');<br>'
var b2="document.write(\"'+a1+''+a2'\");"
var z=a1+a2+b1+b2;
with(document){write(z);} //--></script>
</body></html>

Jul 23 '05 #2

P: n/a
asd987 wrote:
a1='This text (a1) contains the single (') and the double (") quote
and is placed between single quotes. How can I display this variable
using document.write?'

a2="This text (a2) contains the single (') and the double (") quote
and is placed between double quotes. How can I display this variable
using document.write?"

a1='This text (a1) contains the single (\') and the double (") quote';
a2="This text (a2) contains the single (') and the double (\") quote";
document.write(""+a1+" "+a2+"");


document.write(a1, ' ', a2);
JW

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.