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

Roland Dong rdong at advance.net
Thu Jul 7 08:06:35 CDT 2005


Tim,

Thanks, all I want to come up with a for loop to replace the hard coded
javascript. Please see the source in this file:
http://www.wiu.edu/users/murbhd/test.html

Even with the help of this list, I haven't been able to achieve what I want.

For example, I tried something like this without success:

startList = function() {
var TIMER;
	//This is the loop I used without success
	  var ids = new Array("tutorials", "scripting", "validation");
        navBar = document.getElementById("nav").rows[0].cells;    
        
        for(x in ids){
        	var id=ids[x];
			var t=TIMER;
			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)
			}
			
			AddHandlers(id);
	

	   }//for ends
	   
	   	function AddHandlers(xID){
			document.getElementById(xID).onmouseover = new
Function("clearTimeout(TIMER);document.getElementById('" + xID +
"').style.visibility='hidden';");
			document.getElementById(xID).onmouseover = new
Function("TIMER=setTimeout(document.getElementById('" + xID +
"').style.visibility='visible', 500)");

		}
		
//document.getElementById(xID).onmouseover = new
Function("clearTimeout(TIMER);document.getElementById('" + xID +
"').style.visibility="visible';");

}
window.onload=startList;


Thanks for your help.

> -----Original Message-----
> From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu]
> On Behalf Of Timothy White
> Sent: Wednesday, July 06, 2005 5:40 AM
> To: [JavaScript List]
> Subject: Re: [Javascript] A loop for this script? Is it really possible?
> 
> Ok, I'm not 100% sure of what your trying to do.
> >From what it looks like you want to change the value (or add it) of
> onmouseover to execute a function.
> Firstly is the function that you are putting in there dynamic?
> I think that you have two options. First, create the function and use
> document.getElementById(id).onmouseover = "function();";
> Or use document.getElementById(id).setAttribute("onmouseover",
> "function();");
> Try something along those lines.
> 
> Or as I said, I don't 100% understand you.
> 
> Hope it helps
> 
> Tim
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list