View Full Version : Proper Quoting

01-09-2007, 09:48 PM
I'm having a little trouble with my script and I've narrowed it down, hopefully, to this line of code. I believe it is because the quoting is wrong. I'm having a little bit of trouble getting it right, can someone give me a hand?

var tempcontainer=galleryarray[i][3]!=""? '<a href="javascript:popImage('+galleryarray[i][3]+','+galleryarray[i][1]+')">' : ""

The end result should look like this as the link:
javascript:popImage('photo_album/1.jpg','optional title')

The array is setup as follows:

var galleryarray=new Array()
galleryarray[0]=["photo_album/1.jpg", "optional title", "optional description", "photo_album/1.jpg"]

01-09-2007, 10:44 PM

var tempcontainer=galleryarray[i][3]!=""? '<a href="javascript:popImage(\"'+galleryarray[i][3]+'\",\"'+galleryarray[i][1]+'\")">' : ""

01-09-2007, 11:11 PM
I think there still might be a slight problem. The outside delimiter is single quote for that part of the statement but the double quote is the part that is escaped. I could be wrong but, just in case it doesn't work, here it is with the escaped double quotes swapped out or escaped single quotes.

var tempcontainer=galleryarray[i][3]!=""? '<a href="javascript:popImage(\''+galleryarray[i][3]+'\',\''+galleryarray[i][1]+'\');">' : "";


01-09-2007, 11:12 PM
The double quote is escaped because it is passing the 2nd parameter (a string value) to the function. But the href is also surrounded by double quotes. So, the double quotes to pass the strings to the function are all escaped so they don't prematurely end the href.

01-10-2007, 03:11 PM
It works!! Thank you both!