473,382 Members | 1,766 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,382 software developers and data experts.

Single and double quote problems.

Hi all. This isn't quite the same single/double-quote problem we see
posted a multitude of times in this ng. Read on...

I have a js function called ShowActiveLink which accepts a string
containing the full "<a href...>" element. My problem is that some of
the hrefs contain both single and double quotes and I don't have the
ability to escape these characters manually because our content
management system inserts the href when it generates the site.
Therefore I end up with code like this:

<script language="javascript">
void ShowActiveLink('<a
href="javascript:newWindow('http://www.vre.org/');">VRE Service
Status</a>');
</script>
<a href="javascript:newWindow('http://www.vre.org/');">VRE Service
Status</a></li>

....which causes a compiler error.

(Incidentally, the function searches for the current page name inside
the provided href string. If it's found it displays a <li
style="list-style-image: url('images/arrow-right.gif');"> before the
link. Otherwise, it displays an <li> without a bullet.)

Do any of you know a function or something that I can wrap around this
href to escape the string, regardless of how many single or
double-quotes there are, before it is passed to the function?

Thanks,
--Diarmaid.
Jul 23 '05 #1
2 4218
On 10 Nov 2004 06:37:45 -0800, Diarmaid McGleenan
<ca************@yahoo.com> wrote:
Hi all. This isn't quite the same single/double-quote problem we see
posted a multitude of times in this ng. Read on...
Actually, I think it is, but in any case it is the same question you
posted yesterday. I won't repeat everything I wrote then so if you haven't
done so already, please read my previous post.

[snip]
Do any of you know a function or something that I can wrap around this
href to escape the string, regardless of how many single or
double-quotes there are, before it is passed to the function?


This is a *syntax* error. No amount of function calls can correct that,
only modification of the script itself. You will either have to instruct
your content management system (which I believe you blamed yesterday) to
output \" or \' when writing the string literal, or modify the output
afterwards.

Syntax has to be correct *before* it gets to the client. You can't correct
it afterwards.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Thanks for your suggestion Michael, and sorry about the double post
for the same problem. I thought the other message didn't make it to
the ng for whatever reason.

--Diarmaid.
Hi all. This isn't quite the same single/double-quote problem we see
posted a multitude of times in this ng. Read on...


Actually, I think it is, but in any case it is the same question you
posted yesterday. I won't repeat everything I wrote then so if you haven't
done so already, please read my previous post.

[snip]
Do any of you know a function or something that I can wrap around this
href to escape the string, regardless of how many single or
double-quotes there are, before it is passed to the function?


This is a *syntax* error. No amount of function calls can correct that,
only modification of the script itself. You will either have to instruct
your content management system (which I believe you blamed yesterday) to
output \" or \' when writing the string literal, or modify the output
afterwards.

Syntax has to be correct *before* it gets to the client. You can't correct
it afterwards.

Mike

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Joshua Beall | last post by:
Hi All, I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards...
2
by: girish | last post by:
In my XML document, some node attributes data contains both single quot and double quote characters, such as <input msg="Hello "World", What's up"/>. The double quotes are in form of escape...
4
by: sankofa | last post by:
hi, i can't seem to be able to escape my single quote properly... is it even possible in javascript? this is a portion of my code.. var DLEWIS="Pastor Lewis"; .... Sermon is a yser-defined...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
4
by: Greg | last post by:
I keep getting an error when I have a tick mark in a text value that I am searching for in my XPath Query. Example: <Authors> <Author LastName="O'Donnel"> <Author LastName="Smith">...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
4
by: Justin Fancy | last post by:
Hi everyone, I need to replace all instances of a double quote(") with two single quotes('') in a text file. I already have some replacements of strings going on, but I tried this one, but the...
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
3
by: Eric Layman | last post by:
Hi, I've saved data into the db by doing a replace() on single quote. Right now on data display on a datagrid, it shows double single quote. How do I make changes during run time of datagrid...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.