473,883 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

', ", \", then what?

dynamically creating a number of thumbnails, which is working fine. However,
they are supposed to call a function loadRightFrame when clicked, and I seem
to be running into syntax problems. This code:
pagecontent+='< img width="70" height="70" border="0" src="' + thumbArray[i]
+ '" onClick="loadRi ghtFrame(\"' + photoArray[i] + '\")">'

resolves to this:

pagecontent+='< img width="70" height="70" border="0"
src="pictures/unt/kl1.jpg" onClick="loadRi ghtFrame("pictu res/unt/gr1.jpg")">

I obviously cannot use double quotes OR single quotes when passing
parameters to the loadRightFrame function. Escaping the quotes is not
working either. Any ideas?
Greets,

A


Jul 23 '05 #1
3 1382
"Alias" <no@spam.org> writes:
pagecontent+='< img width="70" height="70" border="0" src="' + thumbArray[i]
+ '" onClick="loadRi ghtFrame(\"' + photoArray[i] + '\")">'

resolves to this:

pagecontent+='< img width="70" height="70" border="0"
src="pictures/unt/kl1.jpg" onClick="loadRi ghtFrame("pictu res/unt/gr1.jpg")">
Try:
pagecontent+='< img width="70" height="70" border="0" src="' + thumbArray[i]
+ '" onClick="loadRi ghtFrame(\'' + photoArray[i] + '\')">'

So it's: ', ", \', \\\", \\\\\', ...

Try:
---
var foo = 42;
var s = '"\'\\\"\\\\\'f oo\\\\\'\\\"\'" ';
alert(s);
while (typeof s == "string") {
s = eval(s);
alert(s);
}
---
I obviously cannot use double quotes OR single quotes when passing
parameters to the loadRightFrame function. Escaping the quotes is not
working either. Any ideas?


Escape single quotes.

When in doubt about something like this, I prefer to move backwards.
Start with the desired result, and then add quotes around it add
appropriate escapes.

Start with valid HTML (except the dynamic parts, which we mark so
we can remember where they are):
---
<img width="70" height="70" border="0"
src="{thumbArra y[i]}" onClick="loadRi ghtFrame('{phot oArray[i]}')">
---
Then put it in quotes of some sort. Since the string contains fewest
single quotes, that's what we'll use. That means that existing
single quotes must be escaped (if put double quotes around it, then
we would have to escape all double quotes). If there were any
backslashes, they would have to be escaped as well.
---
'<img width="70" height="70" border="0"' +
' src="{thumbArra y[i]}" onClick="loadRi ghtFrame(\'{pho toArray[i]}\')">'
---
Now the valid HTML has become a valid Javascript string. We can then
insert the dynamic parts, and the surrounding context:
---
pagecontent += '<img width="70" height="70" border="0"' +
' src="'+thumbArr ay[i]+'" onClick="loadRi ghtFrame(\''+ph otoArray[i]+'\')">'
---
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
Lasse Reichstein Nielsen <lr*@hotpop.com > writes:
Try:
---
var foo = 42;
var s = '"\'\\\"\\\\\'f oo\\\\\'\\\"\'" ';


Actually, following the method I gave below, this would become:
---
var s = '"\'\\"\\\\\'fo o\\\\\'\\"\'"';
---
which is two needless backslashes shorter.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3
Lasse Reichstein Nielsen wrote:
|| Lasse Reichstein Nielsen <lr*@hotpop.com > writes:
||
||| Try:
||| ---
||| var foo = 42;
||| var s = '"\'\\\"\\\\\'f oo\\\\\'\\\"\'" ';
||
|| Actually, following the method I gave below, this would become:
|| ---
|| var s = '"\'\\"\\\\\'fo o\\\\\'\\"\'"';
|| ---
|| which is two needless backslashes shorter.
||
|| /L
|| --
|| Lasse Reichstein Nielsen - lr*@hotpop.com
|| DHTML Death Colors:
|| <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html> 'Faith
|| without judgement merely degrades the spirit divine.'

Thanks Lasse, working now.
Jul 23 '05 #4

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

Similar topics

1
8070
by: David Furey | last post by:
Hi I have an XML documnet and a XSLT document as shown below THe XSLT document brings back a filtered docmument that has the VendorName that starts with a particular sub-string This works as expected with alphabet and number characters and the ' (single quote &apos; entity) character but does not work if a double quote character " is part of the string to filter on This returns all Vendor Names that begin with A (either case)
3
3652
by: NecroJoe | last post by:
I am using PHP to generate a little javascript for one of my pages. In short it allows a user to select a value from a list and pop it into a form field on a seperate page. This works well unless there is a " or ' in the character string. <SCRIPT language=JavaScript> function Add_Term(SearchTerm) { window.opener.document.advsearch.name_title.value += SearchTerm; window.close();
8
10669
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at the same time and set different values? Thank you for suggestions!
81
7381
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
4
3763
by: Luke Wu | last post by:
I am just wondering what the following terms usually mean: 1) "Standard C" 2) "K&R C" 3) "ANSI C" I am pretty sure "ANSI C" usually refers to the C89 standard, but what
5
3451
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot; &lt;me@mydomain.com&gt;</Address> </Addresses>
7
3294
by: RFS666 | last post by:
Hello, I would like to use variables with a type in jscript.NET. I declare them as follows: var x : double = 5.03; This doesn't work in my script, that I write to the page in codebehind with "registerClientScriptBlock" as follows: string script = "<script language=jscript>"; script += "function test()";
3
18151
by: Bsr | last post by:
What is the difference between for the following methods. "GET", "HEAD", "PUT" or "POST". Ex:my $req =HTTP::Request->new(GET =>$url1); Bhuvan.
8
3626
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n <br>mais pour avoir des resultats probant il faut pas faire les mariolles, comme le &quot;fondateur&quot; de bvs
3
1925
by: eBob.com | last post by:
How does a "sub-form", i.e. one invoked by another form, determine anything about the form which brought it into existence, i.e., I suppose, instantiated it? I wanted to so something like this ... MsgBox("called by " & Owner.Name) .... but that throws a null reference exception. Parent.Name and ParentForm.Name also throw null reference exceptions. Form1.Name works - but that's not very flexible.
0
9953
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10422
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
9588
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7980
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
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
5808
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
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3242
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.