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 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Set imgage src in function

    Hello, I am a php programmer and so I am not the best with JS. With that said, I have a page with an iframe.


    The iframe holds thumbnails. When you click on a thumbnail, I would like for it to change the image on the parent page. So my issue is that I do not know how to set the img src inside my function. Here is what I have

    Code:
    function SetLargeImage(SRC)
    {
    var idsplit=SRC.split(/_/);
    var imageid=idsplit[1];
    //alert(imageid);
    parent.document.getElementById('M_1').src='http://www.mysite.net/gallery/medium/M_\'+imageid+\'.jpg';
    
    }
    here is the call. This is the one of the thumbnails. In the parent page, the img tag that I am trying to set the source to has the id of M_1

    Code:
    <img id=\"T_".$row["ImageID"]."\" src=\"http://www.mysite.net/gallery/thumbs/T_".$row["ImageID"].".jpg\" onclick=\"SetLargeImage(this.id);\" >

    Here is the img tag on my parent page
    Code:
    <img id="M_1" name="M1" border="0" />
    THank you for any help with this
    Last edited by tripwater; 01-12-2007 at 06:46 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    hey there trip....


    the above code:

    Code:
    function SetLargeImage(SRC)
    {
    var idsplit=SRC.split(/_/);
    var imageid=idsplit[1];
    //alert(imageid);
    parent.document.getElementById('M_1').src='http://www.mysite.net/gallery/medium/M_\'+imageid+\'.jpg';
    
    }
    should look like so:

    Code:
    function SetLargeImage(SRC)
    {
    var idsplit=SRC.split(/_/);
    var imageid=idsplit[1];
    //alert(imageid);
    parent.document.getElementById('M_1').src='http://www.mysite.net/gallery/medium/M_'+imageid+'.jpg';
    
    }
    if you are trying escape the single quote becasu of php, try using double quotes instead.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks brandonH, I knew it had to be something simple...


  •  

    Posting Permissions

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