Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-08-2002, 06:34 PM   PM User | #1
sundance
New to the CF scene

 
Join Date: Jun 2002
Location: Silicon Valley
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
sundance is an unknown quantity at this point
JavaScript string variables

I have noticed that when I place a string with quotes within another quote, browser gets confused, For example:

var test='This is a test for another "<b>Test</b>" from another "<a>world</a> and another time';

When I use the test variable in the JS, string doesn't appear in the browser. If I use a simple variable w/ no quotes or tags inside, string appears fine.

I'm using IE 6.0.26
sundance is offline   Reply With Quote
Old 07-08-2002, 06:42 PM   PM User | #2
Bosko
Regular Coder

 
Join Date: Jun 2002
Location: The Netherlands
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Bosko is an unknown quantity at this point
If the string starts with a double quote (") you can use single quotes inside the string,and you have to escape the double quotes.

var test="This is a test for another \"<b>Test</b>\" from another \"<a>world</a> and another time";
Bosko is offline   Reply With Quote
Old 07-08-2002, 07:25 PM   PM User | #3
sundance
New to the CF scene

 
Join Date: Jun 2002
Location: Silicon Valley
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
sundance is an unknown quantity at this point
Can't I use double quotes within double quotes with escape character?
sundance is offline   Reply With Quote
Old 07-08-2002, 08:53 PM   PM User | #4
premshree
Regular Coder

 
Join Date: Jun 2002
Location: Mumbai, India
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
premshree is an unknown quantity at this point
I would suggest that if you use special characters, instead of using the character itself, it would be better to use the codes for them. For eg the double quote(") has a code &quot;

Codes for other characters are also available.
premshree is offline   Reply With Quote
Old 07-08-2002, 09:14 PM   PM User | #5
sundance
New to the CF scene

 
Join Date: Jun 2002
Location: Silicon Valley
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
sundance is an unknown quantity at this point
Can you please explain in an example what you mean by code?
sundance is offline   Reply With Quote
Old 07-08-2002, 09:58 PM   PM User | #6
ObiwanJebroni
New Coder

 
Join Date: Jun 2002
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
ObiwanJebroni is an unknown quantity at this point
The code of a character is an ampersand (&) followed by its code, followed by a semicolon ( ; ). For instance to get the copyright symbol, you enter:

Code:
& + copy + ;
You'd write that all together without the plus signs, its just that this forum accepts the code and changes them so you can't see the code.

Which results in &copy;.

The code for the quotes he's referring to is ampersand, followed by the word "quot" and the semicolon. Just insert that and it will produce a quote that is automatically escaped in HTML. See:

&quot;I used the code for quotes!&quot;
__________________
-Obiwan Jabroni
May the Schwartz be With You

Last edited by ObiwanJebroni; 07-08-2002 at 10:01 PM..
ObiwanJebroni is offline   Reply With Quote
Old 07-09-2002, 10:57 PM   PM User | #7
sundance
New to the CF scene

 
Join Date: Jun 2002
Location: Silicon Valley
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
sundance is an unknown quantity at this point
Where can I get the listing of these codes? Is there a webpage?
sundance is offline   Reply With Quote
Old 07-09-2002, 11:03 PM   PM User | #8
adios
Senior Coder

 
Join Date: Jun 2002
Posts: 1,404
Thanks: 2
Thanked 32 Times in 32 Posts
adios is on a distinguished road
Resource:

http://www.bbsinc.com/symbol.html

Their actual name is "character entities".

I don't get this thread: your original question was a perfectly good one and, yes, you can escape (literal) quotes within other (delimeter) quotes easily, Bosko's original answer.
adios is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:48 AM.


Advertisement
Log in to turn off these ads.