/    Sign up×
Community /Pin to ProfileBookmark

Javascript error: Obj has no properties

I have a number of show/hide images on my site which allows the user to click on various thumbnails to open up the full image using layer based styles.

However, my Javascript seems to have developed an error saying that the object has no properties and then takes me to the following line of code:

obj.visibility=’hidden’;

This code was written for me so that i could use the script dynamically with PHP an alter the number of div layers it needed to generate.

The full(?) javascript for this function is:
[COLOR=DarkRed]
function showImg(myShow)
{
var loopNum=99;
for (x=1; x<=(loopNum); x++) //1 based loop
{
myImg = “image” + x;
if ((obj=MM_findObj(myImg))!=null)
{
if (obj.style){obj=obj.style;}
}
if (x == myShow)
{//show it!
obj.visibility=’visible’;
}else{//hide it!
obj.visibility=’hidden’;
}
}
}[/COLOR]

I would be enorumously grateful if someone could help me here to pinpoint the error. Let me know if I have missed out any detail/code

Lee

to post a comment
JavaScript

22 Comments(s)

Copy linkTweet thisAlerts:
@DarkRedSpiralAug 18.2005 — Lee

can you give us the code for function MM_findObj(myImg) as it is this

that set the value of obj and it is a bug in there that could well be the

cause of your problems.

Steve
Copy linkTweet thisAlerts:
@Orc_ScorcherAug 18.2005 — You need to nest the 'if (x == myShow)' block inside the 'if ((obj = ...)' block.
Copy linkTweet thisAlerts:
@tintin2002authorAug 18.2005 — Lee

can you give us the code for function MM_findObj(myImg) as it is this

that set the value of obj and it is a bug in there that could well be the

cause of your problems.

Steve[/QUOTE]


I think this is what you are looking for:

[COLOR=DarkRed]function MM_findObj(n, d) { //v4.01

var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

if(!x && d.getElementById) x=d.getElementById(n); return x;

}

[/COLOR]




I have included the following code which is still in my file but I think it is redundant now:

[COLOR=Green]

function MM_showHideLayers() { //v6.0

var i,p,v,obj,args=MM_showHideLayers.arguments;

for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

if (obj.style) { obj=obj.style; v=(v=='show')?'visible'?v=='hide')?'hidden':v; }

obj.visibility=v; }

}

[/COLOR]




Thanks Steve!
Copy linkTweet thisAlerts:
@tintin2002authorAug 18.2005 — You need to nest the 'if (x == myShow)' block inside the 'if ((obj = ...)' block.[/QUOTE]

Thanks, but could you explain it in another way please?
Copy linkTweet thisAlerts:
@Orc_ScorcherAug 18.2005 — That's what you have now, more readable:function showImg(myShow)
{
var loopNum=99;
for (x=1; x&lt;=(loopNum); x++) //1 based loop
{
myImg = "image" + x;
if ((obj=MM_findObj(myImg))!=null)
{
if (obj.style){obj=obj.style;}
}
if (x == myShow)
{//show it!
obj.visibility='visible';
}else{//hide it!
obj.visibility='hidden';
}
}
}
It should be nested like this:function showImg(myShow)
{
var loopNum=99;
for (x=1; x&lt;=(loopNum); x++) //1 based loop
{
myImg = "image" + x;
if ((obj=MM_findObj(myImg))!=null)
{
if (obj.style){obj=obj.style;}

<i> </i> if (x == myShow)
<i> </i> {//show it!
<i> </i> obj.visibility='visible';
<i> </i> }else{//hide it!
<i> </i> obj.visibility='hidden';
<i> </i> }
<i> </i> }
<i> </i>}
}
Copy linkTweet thisAlerts:
@tintin2002authorAug 18.2005 — Thanks for that modification, It works now that I have modified the curly braces but in doing so I have now created another issue:

With the error, the onmousedown command (attached to the thumbnail) INSTANTLY displayed the main image. With this modification, it takes over a second for the image to appear. What's up with that?

Just curious: Both ie6 and Firefox worked with the javascript error (though ie6 says 'with errors' at the bottom). Does it really matter if javascript has errors just so long as it works?

Cheers!
Copy linkTweet thisAlerts:
@Orc_ScorcherAug 19.2005 — Well, I'd say having that script error warning icon on your page looks quite amateurish. I don't know how many images you actually have on your page, lets say 10: In that case the fixed code has to do 10 times as much work and the MM_findObj function is a slow beast.

If you are just interested in finding IMG tags, try replacing 'obj=MM_findObj(myImg)' with 'obj=document.images[myImg]', that should give a nice performance boost.
Copy linkTweet thisAlerts:
@tintin2002authorAug 19.2005 — Well, I'd say having that script error warning icon on your page looks quite amateurish. I don't know how many images you actually have on your page, lets say 10: In that case the fixed code has to do 10 times as much work and the MM_findObj function is a slow beast.

If you are just interested in finding IMG tags, try replacing 'obj=MM_findObj(myImg)' with 'obj=document.images[myImg]', that should give a nice performance boost.[/QUOTE]


Firstly I want to thank you for your support in helping me repair my galleries with this javascript issue. I had no idea that the function was slow. All this is beyond my javascript knowledge (i have just graduated!) so I am struggling to understand. If you don't mind I would like to ask some specific questions based on your reply:
[list=1]
  • [*]What do you mean to say my script error warning icon looks amatuerish?

  • [*]Are you saying just to replace 'obj=MM_findObj(myImg)' with 'obj=document.images[myImg]' - this i did but now it does not work at all!

  • [*]Does it matter if the page has javascript errors? Is just that before it worked - and it worked fast! (I have upto 60 thumbs and the same in full size images on a page.)

  • [/list]


    Or maybe there is a better function for doing what I am trying to do?

    Thanks again!
    Copy linkTweet thisAlerts:
    @Orc_ScorcherAug 20.2005 — 
    [*]What do you mean to say my script error warning icon looks amatuerish?

    [/quote]
    Well, when a script produces an error, IE show a yellow exclamation mark in the bottom left corner and the message "Error on page" in the status bar, other browsers report the error in the JS console. For the more computer-savy visitors this give the impression the page author has done a poor job; others could be confused: "Have I done something wrong?" "Must I correct this error? How?" "Is the page functional?"

    [*]Are you saying just to replace 'obj=MM_findObj(myImg)' with 'obj=document.images[myImg]' - this i did but now it does not work at all![/quote]? I wasn't very optimistic it would work. Since it don't know what your HTML looks like, I could only make a wild guess.

    [*]Does it matter if the page has javascript errors? Is just that before it worked - and it worked fast! (I have upto 60 thumbs and the same in full size images on a page.)[/quote]See 1. There's certainly a way to this implement fast [b]and[/b] bug-free, but not without seeing the complete page. The least thing you can do is hide this error from your users by including window.onerror = function () { return true }at the beginning of your script.
    Copy linkTweet thisAlerts:
    @tintin2002authorAug 22.2005 — Thanks for the feedback. I will implement the code to hide any javascript errors but I guess prevention is better than cure!

    Listen, I don't know what is in this for you, other than the fact you seem to be an extremely nice guy(?), but I would [B][COLOR=Red]love [/COLOR][/B]you to look at the complete page if that is appropriate and you are willing.

    I have missed out one other issue with the page that I would truly love to solve as I use this code on so many pages; It is used for viewing images - and the user can either do this by clicking on the thumbnails displayed on the left (the javascript then displays the main image as already discussed). The other method is a secondary javascript action that displays the images slideshow style with next and previous buttons. The issue I have is that there is a display conflict with the code when the user switches between the two methods to display the image. Simply put, the user has to wait for the slide show to 'catch up' with the order (this is especially noticable when I have both portrait and landscape images). Does this make sense?

    If you can look I would happily post the code or post a link (i don't know what the correct protocol is for this) and if you were ever in Seattle I'd buy you a beer!

    Cheers!
    Copy linkTweet thisAlerts:
    @RahinRedBreastAug 22.2005 — Everyone is willing to help with any JavaScript problem. Just post any (or all) of your code that you want help with here and we will all enjoy flexing our mental muscles at each other over your problem.

    The reason the Orc's speed-up didn't work is that myImg is the *name* of the image not the number. I'll try to explain this.

    document.images[*num*] will access the images in the order that they appear in the document (starting from 0). So, document.images[0] will access the first image, chronologically, in the document. However it has to be a number, not a name.

    So the proper fix should be to put this in the place of "if ((obj=MM_findObj(myImg))!=null)":

    [CODE]if(obj=document.images[x-1]!=null)[/CODE]

    This is assuming that your images are numbered in the order they appear, and that they start from 1.

    give it a try, let us know how you get on, and post anything else you want to.

    Robin.

  • * Edit: By the way, if this works you can delete the line "myImg = "image" + x;" which is now redundant.


  • * Edit 2: Actually, this won't work if you have *any* other images in the document, because it'll find them as well, so the image you're trying to reference won't have the correct reference number. I'll look into the problem and post again. ? sorry. (Although it was orc's idea not mine :p)
  • Copy linkTweet thisAlerts:
    @RahinRedBreastAug 22.2005 — I have been taking a lot of things for granted which should really be questioned.

    I may be being stupid but I don't see why you need all the looping 98 times business. You can, as far as I can see, achieve exactly the same thing with this simple function (which won't take any time at all):

    [CODE]function showImg(myShow) {
    myImg = "image" + myShow;
    MM_findObj(myImg).style.visibility="visible";
    }
    [/CODE]

    Assuming that when you call 'showImg(1)' the image you are hoping to reveal will have the name tag "image1":

    [code=html]<img src="..." name="image1" visibility="hidden" />[/code]

    If this is the case then this will work fine on it's own.

    Admittedly if there isn't an image with the corresponding name tag then it will throw the javascript error "MM_findObj(myImg) has no properties", but I assume that the method will only be called from static documents and therefore if the image doesn't exist you probably want it to throw an error to alert you anyway.

    Let me know if there's some reason why this won't work. And please do post those other problems of yours. I am in the process of learning JavaScript myself and I want some practice.

    Robin.
    Copy linkTweet thisAlerts:
    @montanatonyAug 22.2005 — how can jou cheat at games at javascrit
    Copy linkTweet thisAlerts:
    @RahinRedBreastAug 22.2005 — Montanatony, unless it's extremely badly written u can't. Now why don't you just play the games properly.

    Okay back to the main problem. Now, as I stated above, my little script doesn't really work. However I have a couple of options which will run faster than the current solution. I'll put the current solution here for reference:
    [CODE]function showImg(myShow)
    {
    var loopNum=99;
    for (x=1; x<=(loopNum); x++) //1 based loop
    {
    myImg = "image" + x;
    if ((obj=MM_findObj(myImg))!=null)
    {
    if (obj.style){obj=obj.style;}

    if (x == myShow)
    {//show it!
    obj.visibility='visible';
    }else{//hide it!
    obj.visibility='hidden';
    }
    }
    }
    }[/CODE]

    Okay, numero uno. I believe that this could run significantly faster just by moving the curly brace at the end of "if (obj.style){obj=obj.style;}" to encompass the whole of that block. Here is my (differently formatted) version of this solution:
    [CODE]function showImg(myShow) {
    var loopNum=99;
    for (x=1; x<=(loopNum); x++) { //loop 99 times
    myImg = "image" + x; //create image name
    if (obj=MM_findObj(myImg)) {
    if (obj.style){
    obj=obj.style;
    if (x == myShow) obj.visibility='visible';
    else obj.visibility='hidden';
    }
    }
    }
    }[/CODE]

    My other idea was to go with the document.images idea but modify it so it would have the same functionality. This should be faster because it doesn't have to test every object in the document, just the images. Here it is:
    [CODE]function showImg(myShow) {
    myImg = "image" + myShow;
    var currentImg = document.images;
    var i = 0;
    while(currentImg[i]) {
    if(currentImg[i].name==myImg) currentImg[i].style.visibility="visible";
    else currentImg[i].style.visibility="hidden";
    i++;
    }
    }[/CODE]

    I believe this second solution should be faster, but I don't have a html page with 60 or so images to test it on, and I can't be bothered to make one. so try them out. It's easy, just copy the script exactly as it is from here and overwrite the current "showImg()" function in your javascript (making sure you've backed up first) and then post here to let me know if they work, and which is better,

    Robin.
    Copy linkTweet thisAlerts:
    @tintin2002authorAug 23.2005 — function showImg(myShow)
    {
    var loopNum=99;
    for (x=1; x<=(loopNum); x++) //1 based loop
    {
    myImg = "image" + x;
    if ((obj=MM_findObj(myImg))!=null)
    {
    if (obj.style){obj=obj.style;}

    if (x == myShow)
    {//show it!
    obj.visibility='visible';
    }else{//hide it!
    obj.visibility='hidden';
    }
    }
    }
    }[/CODE]

    Okay, numero uno. I believe that this could run significantly faster just by moving the curly brace at the end of "if (obj.style){obj=obj.style;}" to encompass the whole of that block. Here is my (differently formatted) version of this solution:
    [CODE]function showImg(myShow) {
    var loopNum=99;
    for (x=1; x<=(loopNum); x++) { //loop 99 times
    myImg = "image" + x; //create image name
    if (obj=MM_findObj(myImg)) {
    if (obj.style){
    obj=obj.style;
    if (x == myShow) obj.visibility='visible';
    else obj.visibility='hidden';
    }
    }
    }
    }[/CODE]

    My other idea was to go with the document.images idea but modify it so it would have the same functionality. This should be faster because it doesn't have to test every object in the document, just the images. Here it is:
    [CODE]function showImg(myShow) {
    myImg = "image" + myShow;
    var currentImg = document.images;
    var i = 0;
    while(currentImg[i]) {
    if(currentImg[i].name==myImg) currentImg[i].style.visibility="visible";
    else currentImg[i].style.visibility="hidden";
    i++;
    }
    }[/CODE]

    I believe this second solution should be faster, but I don't have a html page with 60 or so images to test it on, and I can't be bothered to make one. so try them out. It's easy, just copy the script exactly as it is from here and overwrite the current "showImg()" function in your javascript (making sure you've backed up first) and then post here to let me know if they work, and which is better,

    Robin.[/QUOTE]

    Thanks a lot Robin - this was so much appreciated!

    Ok, the results are as follows:

    The first solution worked - though not as fast as the original version with the javascript error (but faster than the solution suggested by Orc Scorcher). Anyhow, it is an acceptable speed but quicker would be better.

    The second solution did not work; the javascript was set to hide all images on mouseover, and that's exactly what it did do - including the thumbnails! So left with a pretty blank page after first image was clicked on. Maybe there is a way to get the just the main images to hide (CSS styles?).

    The conflict with my other javascript slideshow is still apparent. What I will do tomorrow (Tues) is to post a mock site with the two solutions on so that you can see how it works and also to exemplify the javascript conflicts between the thumbnail click to display the main image and the slideshow buttons (forward and back) to display the same images. If a User switches between the two methods, then the correct image gets out of sync.

    Maybe a visual example would be better to explain like I said, but here is the rest of the javascript which works the thumbnails (I don't use the fade feature but don't know which lines to delete):


    [CODE]var DHTML = (document.getElementById || document.all || document.layers);
    if ( !DHTML ) alert('Your browser is not capable of displaying this page');
    function getObj(name) {
    if (document.getElementById) {
    this.obj = document.getElementById(name);
    this.style = document.getElementById(name).style;
    } else
    if (document.all) {
    this.obj = document.all[name];
    this.style = document.all[name].style;
    } else
    if (document.layers) {
    this.obj = document.layers[name];
    this.style = document.layers[name];
    }
    }

    function visib(objName, flag) {
    x = new getObj(objName);
    x.style.visibility = (flag) ? 'visible' : 'hidden';
    }



    images = new Array( // The ids of the images generated by php to allow for varying amount of images per page

    'image1',
    'image2',
    'image3','image4');

    var fadeOn = false;
    function setFade(switchFade) {// Fade switch function
    if ( !fadeOn ) {
    prepLyr(images[curImg], true);
    } else { // No fade
    stopFade();
    for ( var i = 0; i < 8; i++ ) {
    prepLyr(images[i], true);
    if ( images[i] != images[curImg] )
    visib(images[i], false);
    }
    }
    fadeOn = switchFade;
    }

    var curImg = 0; // index of the array entry
    var lastImg = 0;
    function changeSlide ( change ) {
    if (!DHTML) return;
    curImg += change;
    if ( curImg < 0 ) curImg = images.length-1;
    else
    if ( curImg >= images.length ) curImg = 0;
    if ( fadeOn ) {
    firstFade = true;
    prepLyr(images[lastImg], true );
    fadeLayer(images[lastImg], 10, 50);
    } else {
    visib(images[lastImg], false);
    visib(images[curImg], true);
    }
    lastImg = curImg;
    }

    var firstFade = true;
    function nextFade() {
    firstFade = false;
    prepLyr(images[curImg], false);
    fadeLayer(images[curImg], -10, 50);
    }

    var clipTop = 0;
    var clipWidth = 150;
    var clipBottom = 0;
    var lyrheight = 0;
    var time,amount,theTime,middle;
    var imageSize = new Array()

    function prepLyr(lyr, vis) {
    if (!DHTML) return;
    x = new getObj( lyr );
    if (document.layers) {
    if ( !imageSize[lyr] ) {
    lyrheight = x.style.clip.bottom;
    clipWidth = x.style.clip.right;
    imageSize[lyr] = lyrheight + 'x' + clipWidth;
    } else {
    lyrheight = parseInt(imageSize[lyr]);
    clipWidth = imageSize[lyr].substr(imageSize[lyr].indexOf('x')+1);
    }
    if ( vis ) {
    clipTop = 0;
    middle = Math.round(lyrheight/2);
    clipBottom = lyrheight;
    } else {
    middle = Math.round(lyrheight/2);
    clipBottom = middle;
    clipTop = middle;
    }
    x.style.clip.top = clipTop;
    x.style.clip.left = 0;
    x.style.clip.right = clipWidth;
    x.style.clip.bottom = clipBottom;
    x.style.visibility = 'show';
    } else
    if (document.getElementById || document.all) {
    lyrheight = x.obj.offsetHeight;
    clipWidth = x.obj.offsetWidth;
    if ( vis ) {
    clipTop = 0;
    middle = Math.round(lyrheight/2);
    clipBottom = lyrheight;
    } else {
    middle = Math.round(lyrheight/2);
    clipBottom = middle;
    clipTop = middle;
    }
    x.style.clip = 'rect('+clipTop+' '+clipWidth+' '+ clipBottom +' 0)';
    visib(lyr, true);
    }
    }

    function fadeLayer(layername, amt, tim) {
    if (!DHTML) return;
    thelayer = new getObj( layername );
    if (!thelayer) return;
    amount = amt;
    theTime = tim;
    realFade();
    }

    function stopFade() {
    if (time) clearTimeout(time);
    }

    function realFade() {
    clipTop += amount;
    clipBottom -= amount;
    if (clipTop < 0 || clipBottom > lyrheight || clipTop > middle) {
    if ( clipTop > middle ) thelayer.style.visibility = 'hidden';
    if ( firstFade ) nextFade();
    return;
    }
    if (document.getElementById || document.all) {
    clipstring = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' 0)'
    thelayer.style.clip = clipstring;
    } else
    if (document.layers) {
    thelayer.style.clip.top = clipTop;
    thelayer.style.clip.bottom = clipBottom;
    }
    time = setTimeout('realFade()',theTime);
    }[/CODE]


    [COLOR=DarkOrange]As I said, I have now created a working dummy of the web page at treacle sponge dot com /slideshow.php. (I thought it would be prudent to break the URL into words..). Here you will see a visual examples I am having with the javascript conflicts. However you do not see a noticeable issue with the thumbnail display speed as I only posted six images (I can do more if this works).

    Please note the conflicts with the two ways of displaying the main images - either by clicking the thumbnail or using the slide show buttons.



    I would really appreciate it if you could look at this and get back to me if you can.



    Thanks once again.[/COLOR]
    ?

    Copy linkTweet thisAlerts:
    @tintin2002authorAug 25.2005 — Is anyone able to help me?
    Copy linkTweet thisAlerts:
    @tintin2002authorAug 27.2005 — I think I have been forgotten about!
    Copy linkTweet thisAlerts:
    @jammindiceSep 05.2005 — ok, this whole setup has gotten way to complicated, your looping and using alot more resources than you should ever need to do something like this.... I was so bored and outraged at the type of coding you were doing i just had to spend the 30 min to register, re-write this whole thing and post it for you.

    I hope you learn better techniques in the future, and let whoever you got that code from that it's bloated and very very nasty. Besides the loop (which you would never need) you were creating 7 (or as many images you had) div tag areas and just showing and hiding them, this is errored thinking. On top of being a memory hog, this is not very scalable, that's why it was taking so long when you used the *correct* code.

    In the example code below i created one "main" image and changed the source image on it. This is a much easier setup (my 129 line page vs. your 434 lines) cuts back on system resources, loads faster, and pretty much is no doubt the better way.

    I'm not trying to rub in your face that mine is better i'm just trying to show you that there is most likely always a simpler way. If your creating something as simple as an image change by clicking (you can add onMouseover, onMouseup, onMousedown... etc very easily) should not require 400+ lines of code....

    I left out a few things like image pre-load, but that's easy stuff that you could add, just trying to get basic functionality across to you here....

    [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Test Slideshow - Mark Weeks Photography</title>
    <style type="text/css" media="screen">
    @import url(http://www.markweeksphotography.com/styles/mwp.css);
    @import url(http://www.markweeksphotography.com/styles/slideshow.css);

    </style>
    <script src="/__utm.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--

    ////////////// Description underneath image ///////////////////////////
    descText = new Array('Test Image 1','Test Image 2','Test Image 3','Test Image 4','Test Image 5','Test Image 6','Test Image 7');

    var curImg = 1; // current image
    var lastImg = 7; // number of images

    ///////////// Move forward or backward one image //////////////////
    function changeSlide ( change ) {
    curImg += change;
    if ( curImg < 1 ){
    curImg = lastImg;
    } else if ( curImg > lastImg ){
    curImg = 1;
    }
    document.main.src= "images/image" + curImg + ".jpg";
    document.getElementById("text").innerHTML = descText[curImg-1];
    }

    ///////////// Move to specific image //////////////////
    function showImg(myShow) {
    curImg = myShow;
    if ( curImg < 0 ){
    curImg = lastImg;
    } else {
    if ( curImg > lastImg ){
    curImg = 0;
    }
    }
    document.main.src= "images/image" + curImg + ".jpg";
    document.getElementById("text").innerHTML = descText[curImg-1];
    }
    </script>
    </head>
    <body>
    <!-- Logo and Title layer -->
    <div id="title">
    <h1 style="text-align:right">Test Slideshow<br />
    <br />
    </h1>
    <hr />
    <h2>Gallery 1</h2>
    </div>
    <!-- Image Area-->
    <div id="image1"> <img class="photo" src="images/image1.jpg" alt="Test Image 1" title="Test Image 1" id="main" />
    <div id="nav" style="background-color:#FFFFCC; border-left:12px solid #FFFFCC; border-bottom:12px solid #FFFFCC">
    <table class="buy">
    <tr>
    <td></td>
    <td></td>
    <td style="padding-left:10px"></td>
    <td><div style="text-align: right; position: absolute; top: 4px; left: 180px;" id="text">Test Image 1</div></td>
    <td style="width:20%"><a href="javascript:changeSlide(1)"><img src="images/nav/right_arrow.gif" alt="Next" class="button" title="Next" /></a></a><a href="javascript:changeSlide(-1)"><img src="images/nav/left_arrow.gif" alt="previous" class="button" title="Previous" /></a></td>
    </tr>
    </table>
    <hr />
    </div>
    </div>
    </div>
    <!-- Thumbnail Area-->
    <div id="thumb_frame">
    <table id="item">
    <tr>
    <td><img src="images/imageTH01.jpg" alt="Test Image 1" onClick="showImg(1)"></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>
    <tr>
    <td><img src="images/imageTH02.jpg" alt="Test Image 2" onClick="showImg(2)"></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>
    <tr>
    <td><img src="images/imageTH03.jpg" alt="Test Image 3" onClick="showImg(3)"></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>
    <tr>
    <td><img src="images/imageTH04.jpg" alt="Test Image 4" onClick="showImg(4)"></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>
    <tr>
    <td><img src="images/imageTH05.jpg" alt="Test Image 5" onClick="showImg(5)"></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>
    <tr>
    <td><img src="images/imageTH06.jpg" alt="Test Image 6" onClick="showImg(6)"></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>
    <tr>
    <td><img src="images/imageTH07.jpg" alt="Test Image 7" onClick="showImg(7)"></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>

    </table>
    </div>
    <!-- end of thumbs-->
    </body>
    </html>[/CODE]
    Copy linkTweet thisAlerts:
    @jammindiceSep 05.2005 — I'm sorry it's even simpler too, you can use php to loop and write out your thumbnail section....

    [CODE]<!-- Thumbnail Area-->
    <div id="thumb_frame">
    <table id="item">

    <?php
    $numImages = 7;
    for ($i=1; $i<=$numImages; $i++){
    if ($i < 10){ $j = "0$i"; }
    echo "<tr>";
    echo "<td><img src='images/imageTH$j.jpg' alt='Test Image $i' onClick='showImg($i)'></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td><hr></td>";
    echo "</tr>";
    }
    ?>
    </table>
    </div>
    <!-- end of thumbs-->[/CODE]
    Copy linkTweet thisAlerts:
    @jammindiceSep 05.2005 — However, if you must have your fancy bloated dhtml stuff, the simple re-write for this function is:
    [CODE]
    function showImg(myShow) {
    if (!DHTML) return;
    curImg = myShow;
    if ( curImg < 0 ) curImg = images.length-1;
    else
    if ( curImg >= images.length ) curImg = 0;
    if ( fadeOn ) {
    firstFade = true;
    prepLyr(images[lastImg], true );
    fadeLayer(images[lastImg], 10, 50);
    } else {
    visib(images[lastImg], false);
    visib(images[curImg], true);
    }
    lastImg = curImg;
    }
    [/CODE]

    NOTE: THIS FUNCTION WAS ALREADY WRITTEN FOR YOU IN THE CODE ITSELF!

    Also note: this would enable fading if you wanted it.....

    The only line i changed was from this:

    curImg += change;

    to this:

    curImg = myshow;

    You were looping before to find the image that was visible then hiding it and making the selected one visible, this is slow and time consuming, especially since your already tracking the last image that was shown with "lastImg". Simply hid the image with id "imagex" and show image with id "imagey". This is better than your prevoius code, but is still bloated with having x number of layers, one for each image.

    The code above is much more scalable, it should be the same speed no matter how many images you have. However it still requires so many layers of <div> tag areas and you should really move to a less bloated version of code, your going to use less bandwidth (especially good for a photo gallery w/someone on dialup), lower server memory usage, and provide an overall better web experience...

    Next time when you post for help, please include all code, or link to a txt file for viewing. This probably would have been solved much sooner if you had done so, as the others would not have been writing code blind.... Remember progarams are groups of code that WORK TOGETHER and everything (though may not seem so) should be available, helping us help you....
    Copy linkTweet thisAlerts:
    @jammindiceSep 05.2005 — sorry, function above is "changeSlide", forgot to mention that...
    Copy linkTweet thisAlerts:
    @mamelukDec 15.2011 — www.compwisdom.com is terrific. There's often all the appropriate info at the suggestions of my fingers. Thank you and maintain up the superior work!
    ×

    Success!

    Help @tintin2002 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.26,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...