473,651 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7958
On 11 Oct 2003 07:22:11 -0700, Ka**********@at tbi.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.javas cript 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">Kath y\'s problem</div>
<script type="text/javascript">
document.write( document.getEle mentById("alpha ").innerHTM L);
document.write( "<br>Kathy\ 's problem");
</script>
</body>
</html>
<html>
<body>
<div id="alpha">Kath y\'s problem</div>
<script type="text/javascript">
document.write( document.getEle mentById("alpha ").innerHTM L);
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="Javas cript">
function Anomaly(textIn)
{
newWindow = window.open(('A nomaly.aspx?des c=' +textIn), 'Anomaly',
'width=650,heig ht=700');
}
</script>

<input type="button" value="Anomaly"
onclick="Javasc ript:Anomaly('K athy'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**********@a ttbi.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="Javasc ript:Anomaly('K athy'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="Anomal y('Kathy\'s apostrophe test')">

Drop the "Javascript :". It doesn't belong there, and it makes no
difference.
Other comments:
<script language="Javas cript">
This should be
<script type="text/javascript">
The type attribute is required in HTML 4 and later.
newWindow = window.open(('A nomaly.aspx?des c=' +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**********@at tbi.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
2136
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 ugly. I suppose it is for a backwards compatible repr, but couldn't we
7
1494
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 ways of doing this: 1. Run an old Win98 or ME box as a bridge between wireless and wired, writing a bridging program in the process, or
6
1118
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 needed a sets construct and they did not have it so I had to create one. I am not sure yet if they have one in 2005 yet BTW... I was dealing with the Dictionary last night and thought it would be a great
17
1626
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 folks writing standards would bother to properly read and understand the other standards that they reference. -- "There's only one thing that will make them stop hating you.
26
1898
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
30846
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 all together in one field. Example: CompanyName Grower Category Product B Orchard -1 Fruits Apples B Orchard -1 Fruits Blackberries B Orchard -1 Vegetables Beans B Orchard -1 Vegetables Other B Orchard -1 Vegetables Peas
15
1294
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
2155
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 evaluated once?
4
1988
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 check.find('something'): do(somethingElse) idiom, which is a bit of a pity I think.
1
1076
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 html code generated into another html page. I (W3C) validated that page and it disclosed my errors. Well, I fixed all the errors and now all the onclicks work. I did this for Supplier Configuration. One "little" problem came out of that. The...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8579
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.