I am making an image gallery with a user preference checkbox that displays a large or jumbo size image when the thumbnail is clicked. I have a form element on the page that looks like this:
<input type="checkbox" name="targetbox" id="pref"
onclick="supersize(this.checked);">
<label for="pref">Supersize Pics</label>
I also have a link and thumbnail like this:
<a href="images/large/image1.jpg"><img src="images/thumbs/image1.jpg" /></a>
The part that is giving me some trouble is the JavaScript. Here is what I was able to cobble together so far:
<script language="JavaScript">
function supersize(checkme) {
if (checkme)
where = "images/super/";
else
where = "images/large/";
for (var i=0; i<=(document.links.length-1); i++) {
document.links[i].href = where;
}
}
</script>
This will replace the links, but not how I need them. Obviously, this will replace the entire href
, and I need to retain the "image1.jpg" so the new link would be something like: "images/super/image1.jpg". I am sure I need to use an array or split the url into two parts or something. That's the part I am having trouble figuring out. Any help would be appreciated.