473,799 Members | 3,137 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 1381
"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
8066
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
3647
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
10653
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
7358
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
3754
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
3450
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
3291
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
18147
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
3621
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
1922
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
9546
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
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10243
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
10030
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
9078
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...
0
6809
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
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
3
2941
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.