...

View Full Version : Set imgage src in function



tripwater
01-12-2007, 06:36 PM
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



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



<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


<img id="M_1" name="M1" border="0" />


THank you for any help with this

brandonH
01-12-2007, 07:05 PM
hey there trip....


the above 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:



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.

tripwater
01-12-2007, 07:14 PM
Thanks brandonH, I knew it had to be something simple...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum