This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > FrontPage Programming > June 2007 > Javascript: Strings with single and double quotes
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Javascript: Strings with single and double quotes
|
|
| Gaspar 2007-06-28, 6:24 pm |
| I really don't get when to use strings with single quotes, double
quotes, replace them by special html characters ("), etc.
Lots of problem arrise when my application outputs some html with a
string contaning single quotes, like "My name is Nick O'Haran", or even
some application-generated javascript code like "alert("This message
it's ok")". For example:
<input type="button" onclick="alert('My name is Nick O'Haran')">
or
<input type="button" onclick="someFunction();alert("This message it's ok")">
When do I have to replace single quotes by ' ?
When do I have to replace double quotes by " ?
When do I have to backslash double quotes (" --> \") ?
Do Firefox and IE6 handle strings the same way?
Thanks in advanced.
| |
| Trevor Lawrence 2007-06-28, 10:16 pm |
|
Maybe a JS expert could give better info, but here goes (in-line)
"Gaspar" <gaspar@no-reply.com> wrote in message
news:Oce5GSXuHHA.1184@TK2MSFTNGP04.phx.gbl...
>I really don't get when to use strings with single quotes, double quotes,
>replace them by special html characters ("), etc.
>
> Lots of problem arrise when my application outputs some html with a string
> contaning single quotes, like "My name is Nick O'Haran", or even some
> application-generated javascript code like "alert("This message it's
> ok")". For example:
>
> <input type="button" onclick="alert('My name is Nick O'Haran')">
I would write
<input type="button" onclick="alert('My name is Nick O'Haran')">
>
> or
>
> <input type="button" onclick="someFunction();alert("This message it's
> ok")">
I would write
<input type="button" onclick="someFunction();alert('This message it's
ok')">
> When do I have to replace single quotes by ' ?
You could use it in
<input type="button" onclick="someFunction();alert('This message it's
ok')">
> When do I have to replace double quotes by " ?
You could use it in
<input type="button" onclick="someFunction();alert("This message it's
ok")">
> When do I have to backslash double quotes (" --> \") ?
When a double quote is open
> Do Firefox and IE6 handle strings the same way?
Not sure
BTW, None of my suggestions are tested, although I have used similar.
The rule seems to be that if a double quote is open, quoting should be done
using single quotes and vice versa.
Or that you can use the HTML code for quote
--
Trevor Lawrence
Canberra
Microsoft MVP - FrontPage
MVP Web Site http://trevorl.mvps.org
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|