Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Proper Quoting

  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Proper Quoting

    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?

    Code:
    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:
    Code:
    var galleryarray=new Array()
    galleryarray[0]=["photo_album/1.jpg", "optional title", "optional description", "photo_album/1.jpg"]

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Try
    Code:
    var tempcontainer=galleryarray[i][3]!=""? '<a href="javascript:popImage(\"'+galleryarray[i][3]+'\",\"'+galleryarray[i][1]+'\")">' : ""

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

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

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It works!! Thank you both!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •