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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.images[imageName] has no properties

Status
Not open for further replies.

rac2

Programmer
Apr 26, 2001
1,871
US
I am using dynamic images in a navigation frame and sometimes the browser is reporting the error document.images['navX'] is null or has no properties. This seems to be a timing problem, as it can be forced by mousing over the navigation links as the page is loading. Whenever it happens the images associated with the first 10 links work OK, but the succeeding ones generate the error.

Here is an example of one navigation item.
Code:
<tr><td>
<img name=&quot;nav7&quot; src=&quot;images/clear8x8.gif&quot; width=&quot;8&quot; height=&quot;8&quot; border=&quot;0&quot; align=&quot;right&quot;></td>
<td height=&quot;20&quot;><font size=&quot;-1&quot;>
<a href=&quot;donations.html&quot; target=&quot;main&quot; onmouseover=&quot;point('nav7')&quot; onmouseout=&quot;noPoint('nav7')&quot;>
Donations</a>  </font></td></tr>

And here is my rollover code.
Code:
<script>
var iNavCurrent = &quot;nav1&quot;;

if(document.images){
	var noPointImage = new Image();
	var pointImage   = new Image();
	var hereNowImage = new Image();
	
	noPointImage.src = &quot;images/clear8x8.gif&quot;;
	pointImage.src   = &quot;images/deltarightgreen8x8.gif&quot;;
	hereNowImage.src = &quot;images/deltaright8x8.gif&quot;;
}


function point(iNav){
	if(document.images){

		//I put this in to avoid the javascript errors. 
		if(document.images[iNav]){
			document.images[iNav].src = pointImage.src;
		}
	}
}


function noPoint(iNav){
	if(document.images){
		if(document.images[iNav]){
			if(iNav == iNavCurrent){
				document.images[iNav].src = hereNowImage.src;
			} else {
				document.images[iNav].src = noPointImage.src;
			}
		}
	}
}


//setNav() is called from the pages in the main frame by onload.	
function setNav(iNav){
	if(document.images){
		if(document.images[iNavCurrent] && document.images[iNav]){
			document.images[iNavCurrent].src = noPointImage.src;
			document.images[iNav].src = hereNowImage.src;
			iNavCurrent = iNav;
		}
	}
}

</script>

Any tips or observations?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top