View Full Version : test HTML object for event handler

07-30-2006, 12:37 AM
We have the following snippet of code:

function buildLink(id, value) {
var url = parent.modelGet(id)
var el = document.getElementById(id)
... code that adds innerText to el
if (el.onchange)


I'm getting an error in IE 7 Beta 3 for the line in red, claiming the "object does not support this property or method". The claim is true, but the point of the if-test in the line above is to insure we only call onchange() for objects that have an onchange() handler.

This code has worked for us for IE6, Firefox, etc. Is this a bug in IE 7 Beta 3? Or are we misusing that if-test?

07-30-2006, 06:26 AM
Try alerting its type if it indeed returns a function pointer.

alert(typeof el.onchange)