473,405 Members | 2,282 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,405 software developers and data experts.

', ", \", 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="loadRightFrame(\"' + photoArray[i] + '\")">'

resolves to this:

pagecontent+='<img width="70" height="70" border="0"
src="pictures/unt/kl1.jpg" onClick="loadRightFrame("pictures/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 1361
"Alias" <no@spam.org> writes:
pagecontent+='<img width="70" height="70" border="0" src="' + thumbArray[i]
+ '" onClick="loadRightFrame(\"' + photoArray[i] + '\")">'

resolves to this:

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

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

Try:
---
var foo = 42;
var s = '"\'\\\"\\\\\'foo\\\\\'\\\"\'"';
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="{thumbArray[i]}" onClick="loadRightFrame('{photoArray[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="{thumbArray[i]}" onClick="loadRightFrame(\'{photoArray[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="'+thumbArray[i]+'" onClick="loadRightFrame(\''+photoArray[i]+'\')">'
---
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.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 = '"\'\\\"\\\\\'foo\\\\\'\\\"\'"';


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

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.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 = '"\'\\\"\\\\\'foo\\\\\'\\\"\'"';
||
|| Actually, following the method I gave below, this would become:
|| ---
|| var s = '"\'\\"\\\\\'foo\\\\\'\\"\'"';
|| ---
|| which is two needless backslashes shorter.
||
|| /L
|| --
|| Lasse Reichstein Nielsen - lr*@hotpop.com
|| DHTML Death Colors:
|| <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.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
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...
3
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...
8
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...
81
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...
4
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
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;...
7
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...
3
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
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 ...
3
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 ......
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: 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
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.