469,268 Members | 1,025 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

UGH! Using escape characters don't work...anyone know why?

Hi, not sure this is the right group, but hoping someone may have
experienced this.

I'm passing html text as a parameter to a javascript. When it has an
apostrophe in it, of course it does parse correctly. BTW, using IE6
and msxml3/4.

Even if I manually escape the ' with \' or '' the browser just sees it
as \' or '' and not as an escaped apostrophe.

This is driving me nuts! Everyone just tells me to escape the
character.

Any clues most welcome!

Thanks, Kathy
Jul 20 '05 #1
5 7813
On 11 Oct 2003 07:22:11 -0700, Ka**********@attbi.com (KathyB) wrote:
I'm passing html text as a parameter to a javascript. When it has an
apostrophe in it, of course it does parse correctly.


If it parses correctly, what's your problem...

You might try actually illustrating your problem with code, or a link,
you're not even telling us how you're "passing html text as a
parameter to a javascript"

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #2
Lee
KathyB said:

Hi, not sure this is the right group, but hoping someone may have
experienced this.

I'm passing html text as a parameter to a javascript. When it has an
apostrophe in it, of course it does parse correctly. BTW, using IE6
and msxml3/4.

Even if I manually escape the ' with \' or '' the browser just sees it
as \' or '' and not as an escaped apostrophe.

This is driving me nuts! Everyone just tells me to escape the
character.

Any clues most welcome!


You need to provide more detail. A link to a page or a small sample
of code that shows the problem would help.
Did you mean to say "of course it does NOT parse correctly" ?

How are you passing the HTML text?

Escape characters have no meaning in HTML.
Escape characters only have meaning in literal text.
They are ignored in text that is already in the value of a variable.
For example, the following code will produce a page reading:

Kathy\'s problem
Kathy\'s problem
Kathy's problem

<html>
<body>
<div id="alpha">Kathy\'s problem</div>
<script type="text/javascript">
document.write(document.getElementById("alpha").in nerHTML);
document.write("<br>Kathy\'s problem");
</script>
</body>
</html>
<html>
<body>
<div id="alpha">Kathy\'s problem</div>
<script type="text/javascript">
document.write(document.getElementById("alpha").in nerHTML);
document.write("<br>Kathy\'s problem");
</script>
</body>
</html>

Kathy\'s problem
Kathy\'s problem
Kathy's problem

Jul 20 '05 #3
Yes, I DID mean that it does NOT parse correctly. Here is an example of
my script and parameter passed.

<script language="Javascript">
function Anomaly(textIn)
{
newWindow = window.open(('Anomaly.aspx?desc=' +textIn), 'Anomaly',
'width=650,height=700');
}
</script>

<input type="button" value="Anomaly"
onclick="javascript:Anomaly('Kathy's apostrophe test')">

QUESTION: What does the parameter have to be to not throw an exception
within the script? I've tried \' but it just results in \' in the html
output not just the html source.

I hope this clarifies my question. Thanks for responding!

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
Kathy Burke <ka**********@attbi.com> writes:
Yes, I DID mean that it does NOT parse correctly. Here is an example of
my script and parameter passed.
<input type="button" value="Anomaly"
onclick="javascript:Anomaly('Kathy's apostrophe test')"> ^
The problem is here: ^
That single-quote/apostrophe must be escaped.
QUESTION: What does the parameter have to be to not throw an exception
within the script? I've tried \' but it just results in \' in the html
output not just the html source.
The onclick event should be:
onclick="Anomaly('Kathy\'s apostrophe test')">

Drop the "javascript:". It doesn't belong there, and it makes no
difference.
Other comments:
<script language="Javascript">
This should be
<script type="text/javascript">
The type attribute is required in HTML 4 and later.
newWindow = window.open(('Anomaly.aspx?desc=' +textIn), 'Anomaly',


Not all characters are allowed in URL's, so I would suggest changing
"textIn" to "escape(textIn)". That will write characters that are
not allowed in URL's as, e.g., %20 (a space).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Ka**********@attbi.com (KathyB) wrote

I think what you're asking is how to nest quotes. For instance, if you
want to use document.write() to write out a statement that has a quote
in it.

If so, the answer is that most places that need quotes, can use either
single quotes or double quotes.

document.write("Kathy's page"); // Quoted string contains
apostrophe
shows up as
Kathy's page

document.write('Is "Kathy" home?"); // Quoted string contains
quote
shows up as
Is "Kathy" home?

If you find that you need to use both, you can use the + sign to
concatenate.

document.write('Is this "Kathy' + "'s Page" +'"?');
shows up as
Is this "Kathy's Page"?

HTH
Hi, not sure this is the right group, but hoping someone may have
experienced this.

I'm passing html text as a parameter to a javascript. When it has an
apostrophe in it, of course it does parse correctly. BTW, using IE6
and msxml3/4.

Even if I manually escape the ' with \' or '' the browser just sees it
as \' or '' and not as an escaped apostrophe.

This is driving me nuts! Everyone just tells me to escape the
character.

Any clues most welcome!

Thanks, Kathy

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Poly-poly man | last post: by
6 posts views Thread by Ray Cassick \(Home\) | last post: by
17 posts views Thread by Ben Pfaff | last post: by
26 posts views Thread by Rajat | last post: by
20 posts views Thread by Sergey Dorofeev | last post: by
Ugh
1 post views Thread by sheldonlg | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.