[Javascript] A loop for this script? Is it really possible?

Roland Dong rdong at advance.net
Tue Jul 5 16:12:49 CDT 2005



Mike,

Based on your idea. I tried something like this:


===========================================================
startList = function() {
var TIMER;
		var ids = new Array("tutorials", "scripting", "validation");
        navBar = document.getElementById("nav").rows[0].cells;    
        
        for(x in ids){
        	var id=ids[x];
			navBar[x].onmouseover=function() {
	
document.getElementById(ids[this.cellIndex]).style.visibility="visible"
			}
			
			navBar[x].onmouseout=function() {
	
TIMER=setTimeout('document.getElementById("'+ids[this.cellIndex]+'").style.v
isibility="hidden"', 500)
			}
			
			attachMouseEvents(id);
	

	   }//for ends
	   
function attachMouseEvents( id ) {
   document.getElementById(id).onmouseover = new Function( "movr(" + id +
")" );
   document.getElementById(id).onmouseout = new Function( "mout(" + id + ")"
);
   }
     
function movr( id ) {
		    clearTimeout(TIMER);
	
document.getElementById(id).style.visibility="visible";
}

function mout( id ) {
TIMER=setTimeout('document.getElementById(id).style.visibility="hidden"',
500); }

}

window.onload=startList;
========================================================================

I still get the error that  movr, mout is not defined..... 

See the complete code: http://www.wiu.edu/users/murbhd/test4.html


Haven't got a chance to read them yet but thanks for the links.



> Subject: Re: [Javascript] A loop for this script? Is it really possible?
> 
> function attachMouseEvents( id ) {
>    document.getElementById(id).onmouseover = new Function( "movr(" + id +
> ")" );
>    document.getElementById(id).onmouseout = new Function( "mout(" + id +
> ")" );
>    }
> 
> function movr( id ) { window.status = "mouseover: " + id }
> function mout( id ) { window.status = "mouseout:" + id }
> 




More information about the Javascript mailing list