Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<Img> - onLoad 1

Status
Not open for further replies.

SH4F33

Programmer
Apr 1, 2005
58
MU
Hello everybody, Im having some issues with the onload event of images.

I have some thumbnails, and when I click on any of them, a row displaying "Loading..." will have its 'display' property set to '' from none, at the same time, an image which has a blank gif will load the larger image.

When the larger image has been loaded, the "Loading..." row will have its display property set to none on the image's onLoad event. It works fine as long as I click on different thumbnails each time.

But if I click on the same thumbnail twice, the "Loading" row will not have its display property change to none on the second click.

Roughly here's the layout:

Code:
Thumb1 | Thumb2 | Thumb3 | Thumb4 ...
======================================
<tr id="theMess" style="display:none">...
               LOADING...          
</tr>
======================================
<img id="hdContainer"...
              LARGER IMAGE

======================================

And here's part of the code I'm working on

Code:
The thumbnail(s):

<a href="#" class="xxx" onclick="hdContainer.src='path/big.jpg';document.getElementById('theMess').style.display='';return false;"><img src="path/small.jpg" /></a>

The larger image:

<img id="hdContainer" src="path/blank.gif" onLoad="document.getElementById('theMess').style.display='none'" />

I guess, when clicking on the tumbnail twice, on the 2nd time, the cached image will be loaded, but still, and image is being loaded, but onLoad="document.getElementById('theMess').style.display='none'" is not being triggered.

Thanks for any input.
 
try it tis way and let me know if there is any problem

Code:
<script language="javascript">
  var loadedPhoto;
  function loadPhoto(myphoto){
    if ( loadedPhoto == myphoto ) {
      return false;
    }
    else {
      document.getElementById('theMess').style.display='visible';
      document.getElementById('hdContainer').src='path/' + myphoto + '_big.jpg';
      loadedPhoto = myphoto;
      return false;
    }
  }
</script>

Code:
<a href="#" class="xxx" onclick="loadPhoto(('photo1');"><img src="path/photo1.jpg" style="border:none;" /></a>
<a href="#" class="xxx" onclick="loadPhoto(('photo2');"><img src="path/photo2.jpg" style="border:none;" /></a>
<a href="#" class="xxx" onclick="loadPhoto(('photo3');"><img src="path/photo3.jpg" style="border:none;" /></a>

<tr id="theMess" style="display:none;">...
               LOADING...          
</tr>

<img id="hdContainer" src="path/blank.gif" onLoad="document.getElementById('theMess').style.display='none'" />


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Thanks a bunch man. Clever function.
Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top