[Javascript] A loop for this script? Is it really possible?
Mike Dougherty
mdougherty at pbp.com
Tue Jul 5 13:31:27 CDT 2005
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 }
I think the proper terminology for what you're doing is creating a 'closure' (i'm not 100% clear
myself, but this solved this exact problem for me recently)
this is what i used to figure it out:
http://jibbering.com/faq/faq_notes/closures.html
http://forums.devshed.com/archive/t-131107/Creating-anonymous-functions
BTW, testing mouse events with alert() is tedious and painful, so I used window.status instead.
On Tue, 5 Jul 2005 12:37:35 -0400
"Roland Dong" <rdong at advance.net> wrote:
>
> Is it possible to pass the value to:
> document.getElementById(value_to_be_passed).onmouseover=function(){....}
>
> I tried many tricks without success. I started wondering if it is really
> possible. I do not understand why it works if you hard coded value:
>
> Document.getElementById("tutorials").onmouseover=function(){....} but you
> can never replace "tutorials" with any dynamic value? I even tried
>
> f="tutorial";
> Document.getElementById(f)onmouseover=function(){....} but it is still not
> working. That drives me nut!
>
>
>
>>A quick fix would be to precalculate the id and put it in the string:
>
>> var id= ids[i];
>> var f= 'document.getElementById("'+id+'").style.visibility= "hidden"';
>> var timer= window.setTimeout(f, 500)
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
>
> __________________________________________________________
> This message was scanned by ATX
> 12:37:42 PM ET - 7/5/2005
More information about the Javascript
mailing list