473,372 Members | 926 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,372 software developers and data experts.

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

Similar topics

6
by: Bengt Richter | last post by:
>>> hex(-5) __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4 and up '0xfffffffb' >>> hex(-5) '0xfffffffb' >>> hex(-5L) '-0x5L' That is sooo...
7
by: Poly-poly man | last post by:
First off, I'd like to say that if you can find a better newsgroup for this message, direct me to it. My problem is this: I need to hook my Linux box up to a wireless network. I thought of two...
6
by: Ray Cassick \(Home\) | last post by:
Ok, what is up here. The 2005 framework contains all kinds of cool new structures now that we have Generics and all but they always seem to fall just short of exactly what I need. In 2003 I...
17
by: Ben Pfaff | last post by:
The Unicode standard says this in section 3.9: "For example, a string is defined as a pointer to char in the C language, and is conventionally terminated with a NULL character." You'd think...
26
by: Rajat | last post by:
The output of "j" in the below code is 8. Can anybody explain me the concept? #include<stdio.h> #include<conio.h> int main(void) { int i=2; int j=0;
46
by: kyjabber | last post by:
I have a multi relationship database and I'm pulling the company's contact info, queryied if they are a grower, and a resulting list of their products by catgeory. I need to have the products listed...
15
by: AJ | last post by:
Why does the following behave as it does...? public class Base { public void Add( byte b ) { } } public class TestClass : Base
20
by: Sergey Dorofeev | last post by:
Hello all! Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be...
4
by: jelle | last post by:
the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if...
1
Ugh
by: sheldonlg | last post by:
(I tried to call) The onclicks not working is definitely due to missing closing tags. The way I found this was to copy a pieces of code and made a mini-app. I then ran that app and copied the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.