onClick replace /segment/ of img src path with one of number of values

heyyo

New Member
No idea what I'm doing or why it isn't working. Clearly not using the right method and probably won't use the right language to explain the problem..Photogallery... Trying to have a single html page... it has links to images... buttons on the page 'aim to' modify the path to the images by finding the name currently in the path and replacing it with the name of the gallery corresponding to the button the user clicked on...example:\[code\]GALLERY2go : function(e) { if(GalleryID!="landscapes") { var find = ''+ findGalleryID()+''; var repl = "landscapes"; var page = document.body.innerHTML; while (page.indexOf(find) >= 0) { var i = page.indexOf(find); var j = find.length; page = page.substr(0,i) + repl + page.substr(i+j); document.body.innerHTML = page; var GalleryID = "landscapes"; } }},\[/code\]There's a function higher up the page to get var find to take the value of var GalleryID:\[code\]var GalleryID = "portfolio";function findGalleryID() { return GalleryID}\[/code\]Clearly the first varGalleryID is global (t'was there to set a default value should I have been able to find a way of referring to it onLoad) and the one inside the function is cleared at the end of the function (I've read that much). But I don't know what any of this means.The code, given its frailties or otherwise ridiculousness, actually does change all of the image links (and absolutely everything else called "portfolio") in the html page - hence "portfolio" becomes "landscapes"... the path to the images changes and they all update... As a JavaScript beginner I was pretty chuffed to see it worked. But you can't click on another gallery button because it's stuck in a loop of some sort. In fact, after you click the button you can't click on anything else and all of the rest of the JavaScript functionality is buggered. Perhaps I've introduced some kind of loop it never exits. If you click on portfolio when you're in portfolio you crash the browser! Anyway I'm well aware that 'my cobbled together solution' is not how it would be done by someone with any experience in writing code. They'd probably use something else with a different name that takes another lifetime to learn. I don't think I can use getElement by and refer to the class/id name and parse the filename [using lots of words I don't at all understand] because of the implications on the other parts of the script. I've tried using a div wrapper and code to launch a child html doc and that come in without disposing of the existing content or talking to the stylesheet. I'm bloody lost and don't even know where to start looking next.The point is... And here's a plea... If any of you do reply, I fear you will reply without the making the assumption that you're talking to someone who really hasn't got a clue what AJAX and JQuery and PHP are... I have searched forums; I don't understand them. Please bear that in mind.
 
Top