[Javascript] Setting event handlers on a dynamically created row

Peter Brunone peter at brunone.com
Fri Mar 12 07:58:11 CST 2004


Hi Håkan,

	Thanks for the idea.  Unfortunately, my implementation seems to
have the same effect as if I had not used the function constructor.  
	However, I did manage to get the element whose event was
triggered, and I can pull its properties from the resulting function.
This works perfectly for what I'm trying to do.

<span id="windowBox" pottedPlant="geranium">Click Me</span>

<script language="Javascript">
function fillSpan() {
	var mySource = window.event.srcElement;
	alert(mySource.id + "     " + mySource.pottedPlant);
	}

// Either of these statements works in IE
document.all.windowBox.onclick = fillSpan;
//document.all.windowBox.attachEvent("onclick", fillSpan);
</script>


Cheers,

Peter
-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Håkan Magnusson

Create an anonymous wrapping function?

rowTemp.onmouseover = new function() { yourFunction(param1, param2, 
param3); };

If I understand you correctly, I think this is the only way to achive 
what you want.

Regards,
Hakan

Peter Brunone wrote:
> 	Okay, so maybe that was a silly question, considering the 
> availability of attachEvent() in later versions of Javascript, but I'd

> still like to know how to point it to a function with parameters.
> 
> Thoughts?
> 
> -----Original Message-----
> From: javascript-bounces at LaTech.edu On Behalf Of Peter Brunone
> 
> Hi all...
> 
> 	If I create a row or a cell on a table, how do I assign
functions 
> (specifically functions with parameters) to its event handlers?  
> Experience tells me that if I assign
> 
> rowTemp.onmouseover = thisFunction(this)
> 
> it will of course assign the *return value* from that function, which 
> of course is wrong.  However, if I assign
> 
> rowTemp.onmouseover = "thisFunction(this)"
> 
> I would think it would be taken as a string, and not as a function.  
> The only other option I can imagine -- using eval() on the string I'm 
> assigning -- would seem to have the same result as the first.  Can 
> anyone shed some light on what I'm supposed to do here?
> 
> Cheers,
> 
> Peter Brunone
> 
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu 
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 
> 
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list