Results 1 to 7 of 7

Thread: Array question...Help!

  1. #1
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array question...Help!

    I am currently modifying a DD script, Image Thumbnail Viewer II. But my question is a generic Javascript question.

    How do I pass a value of an array to a funtion and then read it?

    Exmaple:
    var dynimages=new Array()
    dynimages[0]=["wed01_medium.jpg", "wed01_large..jpg"]

    I want to be able to store the image width and height. I'm not sure but think it should be like this:
    dynimages[0]=["wed01_medium.jpg", "wed01_large.jpg",600,800]

    Now I want to pass the values to the funtion below and replace the width and height values with the one in my array. I can't figure that out. Can someone help?

    function returnimgcode(theimg){
    var imghtml=""
    if (theimg[1]!="")
    imghtml='<a href="'+theimg[1]+'" onclick="window.open(this.href,\'popupwindow\',\'width=500,height=500,scrollbars=no,statusbar=no,resizable=yes,\');return false;" target="_blank">'
    imghtml+='<img src="'+theimg[0]+'" border="'+imgborderwidth+'">'
    if (theimg[1]!="")
    imghtml+='</a>'
    return imghtml
    }


    function modifyimage(loadarea, imgindex){
    if (document.getElementById){
    var imgobj=document.getElementById(loadarea)
    if (imgobj.filters && window.createPopup){
    imgobj.style.filter=filterstring
    imgobj.filters[0].Apply()
    }
    imgobj.innerHTML=returnimgcode(dynimages[imgindex])
    if (imgobj.filters && window.createPopup)
    imgobj.filters[0].Play()
    return false
    }
    }


    THANK YOU!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    imghtml='<a href="'+theimg[1]+'" onclick="window.open(this.href,\'popupwindow\',\'width='+theimg[2]+',height='+theimg[3]+',scrollbars=no,statusbar=no,resizable=yes,\');return false;" target="_blank">'
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    Thanks for your help. I tried the code you provided but I'm getting an error 'theimage' is undefined. Any ideas?

    Thanks,
    Rick

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Take another look at my code, I used:

    theimg

    not

    theimage
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm sorry for the confusion, the error reads, theimg is undefined.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Tested here and works.
    PLEASE: Include the URL to your problematic webpage that you want help with.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    I just copied and pasted the code again and it works like you said. Thanks for all your help!

Bookmarks

Posting Permissions

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