Click to See Complete Forum and Search --> : event handlers and responsible parties...


angrytuna
05-12-2003, 04:35 PM
hello the forum!

I'm having a bit of difficulty determining who's responsible for throwing an event. I come from a Java background where you can use 'this' to determine the class responsible for calling a function. In javascript however, 'this' returns the Window object. If a button named 'bar' had an onclick handler which called 'javascript:foo()', I'd like in the body of foo to reference 'bar' (i.e. bar.name, bar.value, etc). Can anyone help?

~AT

Jona
05-12-2003, 04:48 PM
<input type=button onClick="foo(this)">

function foo(element){
alert(element.type); // returns, "BUTTON"
}

angrytuna
05-12-2003, 05:12 PM
Wonderful! Thanks for the help. :)

~AT

Jona
05-12-2003, 05:20 PM
;)