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

Nested quotation marks/single quotes problem

I have a nested quotes issue I'm trying to resolve. Basically I need a 5th
level nested quote for quoting the string argument to the getXMLFeed()
function in the following:

var myHTML = "<TR onMouseOver='return overlib(\"<A
HREF=\'javascript:void(0)\'
onClick=\'javascript:getXMLFeed(\"price\")\'>Price </A>\"'>";

How do you do a 5th level nested quote?

Level 1: "
Level 2: '
Level 3: \"
Level 4: \'
Level 5: ?!?!?

Thanks,
Dustin
Aug 13 '06 #1
2 18656
Dustin said the following on 8/13/2006 11:19 AM:
I have a nested quotes issue I'm trying to resolve. Basically I need a 5th
level nested quote for quoting the string argument to the getXMLFeed()
function in the following:

var myHTML = "<TR onMouseOver='return overlib(\"<A
HREF=\'javascript:void(0)\'
onClick=\'javascript:getXMLFeed(\"price\")\'>Price </A>\"'>";

How do you do a 5th level nested quote?

Level 1: "
Level 2: '
Level 3: \"
Level 4: \'
Level 5: ?!?!?
You can double escape it, or, have one of your functions do a replace on
the string and use your own delimiter. But the above code looks like a
horrendous way to do something.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 13 '06 #2
On 13/08/2006 16:19, Dustin wrote:

[snip]
var myHTML = "<TR onMouseOver='return overlib(\"<A
HREF=\'javascript:void(0)\'
onClick=\'javascript:getXMLFeed(\"price\")\'>Price </A>\"'>";

How do you do a 5th level nested quote?
Include an escaped backslash: \\\"

The important thing to note here, however, is that you've neglected to
remember that an attribute value cannot contain a literal quotation mark
of the same type to delimit the value itself. That is, instead of writing,

""Thanks", he replied." or "\"Thanks\", he replied."

one must write:

"&quot;Thanks&quot;, he replied."

Likewise if using apostrophes, replacing &quot; with ' :

'That's all, folks!'

HTML neither knows nor cares about backslashes as escape delimiters;
only entities are acceptable.

The end result is string like (manually wrapped and concatenated):

"<tr onmouseover='return overlib(\"<a href='#'"
+ " onclick='getXMLFeed(\\\"price\\\");return"
+ " false;'>Price</a>\");'>"

Or, as I prefer to use double quotes as attribute value delimiters:

'<tr onmouseover="return overlib(\'<a href=&quot;#&quot;'
+ ' onclick=&quot;getXMLFeed(\\\'price\\\');return'
+ ' false;&quot;>Price</a>\');">'

Note that I've removed the use of the javascript pseudo-scheme. Read the
archives for why its use in links is a bad idea.

It might help you in future if you work backwards, starting from (in
this case) the markup you'd really want to pass to the overlib function,
working your way "out" to the markup that would contain that. That said,
it would be easier to move all of that out of the event listener into a
separate function.

Mike
Aug 13 '06 #3

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

Similar topics

1
by: NikkoW | last post by:
I need to assign a string to a variable but the text string includes quotation marks: Example: MyString = "He turned and said "Hello" before leaving." When the compiler hits the quotation...
63
by: Tristan Miller | last post by:
Greetings. Do any popular browsers correctly support <q>, at least for Western languages? I've noticed that Mozilla uses the standard English double-quote character, ", regardless of the lang...
7
by: Paradigm | last post by:
I am trying to create a recordset where some text fields are matching. The problem is that some of the text fields contain quotation marks. I have tried to create the sql string using replace eg....
6
by: mplogue | last post by:
I'm trying to build a function that reads each character in a string and converts it to an ASCII numerical value. So far, so good. However, I'm running into problems when dealing with quotation...
2
by: Dixie | last post by:
Hi, I am tyring to write some generic code that will send the source SQL for a mailmerge to a Word template. I am trying to use DLookup to insert the query name that is the record source for the...
9
by: M P | last post by:
Hi! I am looking for a way that I can trap the single quotation mark. If an encoder uses single quotation mark on a textbox field, it always give me an error because I use single quotes on the...
2
by: bcastaing | last post by:
My Windows service includes the following lines: string Arguments3 = @"%OvAgentDir%\bin\OpC\cmds\ref-ovo-services.vbs ServiceApplicatif ServiceOVO"; string expandedArguments3 =...
31
by: The Bicycling Guitarist | last post by:
Hi. For many years I have been using &quot; for double quotation marks in the HTML code, but the opening and closing quotation marks render the same in my browser. I'm considering going through and...
12
by: Adam Right | last post by:
Hi ! In my sql statement, i have to use field names and table name with quotation marks. like that : ----------------------------------------------------------------------- string sqlStr = ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.