Bricktop Posted August 28, 2008 Share Posted August 28, 2008 Hello all, I am using the below code to display a list of thumnail images, then I'm using some Javascript code to display the full-size image using an "onclick" event. All of this works tickety boo, but when the gallery page loads, because no one has yet clicked a thumbnail, the main image holder on the page just shows a blank box with an ugly image not found red cross. What I would like to do is somehow always show the first image in the set. Is there anyway I can achieve this do you know? I hope so but I'm a little concerned as to the fact that it's an onclick event I'm using. My code is below - I've added a firsrow=true/false line into the loop already - maybe we could work on that? Thanks $sql = mysql_query("SELECT * FROM gallery ORDER BY id"); $firstRow = true; while ($a = mysql_fetch_array($sql)) { $content .= '<li><a href="'.$a['path'].''.$a['filename'].'" onclick="showPicture(this); return false;" title="'.str_replace('"','"',$a[description]).'"><img src="'.$a['thumbnailpath'].''.$a['filename'].'" alt="'.str_replace('"','"',$a[description]).'" /></a></li>'; $firstRow = false; } Quote Link to comment Share on other sites More sharing options...
swamp Posted August 28, 2008 Share Posted August 28, 2008 You could use something like this: <script> function fixBrokenImage(){ var imglst = document.images; for(var i = 0; i < imglst.length; i++){ imglst[i].onerror = function() { this.src = "myimage.gif"; } imglst[i].src = imglst[i].src; } } </script> then use <body onLoad="fixBrokenImage();"> Just change myimage to the image you want to use as default. Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 28, 2008 Author Share Posted August 28, 2008 Hi, thanks Swamp but I don't think it would be dynamic, I would like that image to change if the user uploads a new image. Essentially, the last image to be uploaded will always be theimage shown when the Gallery page loads. Quote Link to comment Share on other sites More sharing options...
swamp Posted August 28, 2008 Share Posted August 28, 2008 Oh sorry - only skimmed through your first post I thought you just wanted to fix it with the same image everytime.. I'll have a look into it for you Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 28, 2008 Author Share Posted August 28, 2008 Hi Swamp, Thanks but just cracked it - the HTML code to show dynamically show the image was: <img id="placeholder" src="" alt="Image Viewer" /> I assumed the "src=" had to be kept blank - I just tried inserting an image URL into that and the image still changes with the onlick event! Thanks for looking into it for me though matey! Quote Link to comment Share on other sites More sharing options...
swamp Posted August 28, 2008 Share Posted August 28, 2008 Cool Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.