473,399 Members | 2,774 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,399 software developers and data experts.

using quotes in variables

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

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
6
by: LRW | last post by:
I have a command I need to run in a shell: /usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB +profile "*" /usr/shipthumbs/*.tif I've tried doing this: $mog = "/usr/bin/mogrify...
9
by: Dynamo | last post by:
Hi, I am still confused as when to use single or double quotes. This works: echo "<td>" . $row . "</td>"; and this does not
4
by: marc.wyburn | last post by:
Hi, I am trying to move away from Windows only scripting to Python. I've written a quick script that will pull the product version from the client registry. I can get the IP addresses from a file...
16
by: Craig L | last post by:
I use ASP to obtain data from a database and I have a piece of javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but...
2
by: Craig L | last post by:
This is a solution followup to a request for help posted on 11/04/03 at 12:51pm titled "Using ASP Variables". Here is how you can make ASP variables available for use in Javascript code. I hope you...
11
by: sm | last post by:
Hi All, Can anybody give me the syntax to insert a record into SQL server through VB code using variables? The following statement is failing! sInsertQuery = "INSERT INTO TestTab (Col1, Col2,...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
9
by: Dave-o | last post by:
New learner. For the print command and concatenation, the period is difficult for my afflicted eyes to see, but the "+" seems to work. Is this an accepted PHP convention? Thank you, David
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...

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.