I'm sure I've done this before, but I can't find where it is... I have a photo album with images whose names end with _Thumb. I then have those same images in the full size without the _Thumb. What I want to do is to have a link on the _Thumb images to call a Javascript. That function would then take the source of the image that was clicked and strip out the _Thumb to get the full size image name. How do I code the javascript to get the src of the selected image?

I've tried using this.src in the function, but I get the value "undefined". I also tried using an onclick event instead of a normal a href, and it still doesn't work.

Chris

02-13-2014, 11:09 PM

JMRKER

Show some code that you have attempted.
Perhaps it works but you have a syntax or typo error.
Make it brief, if possible.

02-14-2014, 12:32 PM

chrscote

I just figured out my problem. I had forgotten to use event.srcElement. Instead, I was just using this.src. So now I have:
function changeImg() {
var clickedImg = event.srcElement.src;
var mainImg = document.getElementById("mainImg");
var newImg = clickedImg.substr(0, clickedImg.indexOf(".")-6); //Take of _Thumb.jpg
mainImg.src = newImg+".jpg";
}

02-15-2014, 01:40 PM

aubenefit

you can use Jquery and get many values from object.
If get value of src, you can use attribute "attr"