On 7/12/12 10:02 AM, MonkeyMargie wrote:
I've tried this:
var elmLink = document.getElementById('MyFieldName');
elmLink.addEventListener("click", sayhello('world'), true);
but it seems to execute only when the page is loaded, not when I click
on the field. I've tried other actions such as 'mousemove', 'change',
etc., but nothing works. Help!
addEventListener accepts a function as its second argument, which is
called when the event occurs. Instead of *passing* a function, you're
*calling* the function sayhello, and passing sayhello's return value to
addEventListener (which is probably undefined, so clicks, or whatever
event you use, are effectively ignored). Instead try:
elmLink.addEventListener("click", function(){sayhello('world');}, true);
That creates an anonymous function and passes it to addEventListener.
When the element is clicked, the browser calls the anonymous function,
which then calls sayhello.
Brian
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.