Not implemented error in IE

Hi,

I'm having this problem just for IE (I'm using IE8). The code works fine in all the other browsers (Firefox, Safari, Chrome). Here is a snippet

// I've a div with id='div_a'

window.onload = function() {
  var elem = document.getElementById('div_a');
  elem.onclick = dosomething(elem);
}

function dosomething(obj) {
  if( !obj ) return;
  obj.onmousedown = function() {
    // doing something over here
  }
}

Please note that window.onload is actually pointing to a function object. It is the same as doing the following (which yielded the same 'Not implemented' error in IE):-

window.onload = init;

function init() {
  var elem = document.getElementById('div_a');
  elem.onclick = dosomething(elem);
}

cavtelAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
You can pass events on the object's onclick but no need to pass the object, and you are not replacing the event handler correctly. You call it as if dosomething would return the new event handler

Here is the correct invocation

 elem.onclick = dosomething;

function dosomething() {
  this.onmousedown = function() {
    // doing something  over here
  }
}
0
 
Michel PlungjanIT ExpertCommented:
HOWEVER I would not try to sset the onmousedown event handler in an onclick event. That is asking for trouble
0
 
Michel PlungjanIT ExpertCommented:
So why a "B" ?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
cavtelAuthor Commented:
My apologies. I thought I had clicked on 'A' and soon I realized my mistake. I don't think it is possible to re-assign a grade? or is it?
0
 
Michel PlungjanIT ExpertCommented:
No problem. Unaccepted
0
 
cavtelAuthor Commented:
I was originally trying to execute a mousedown event when the user triggered a onclick event. But I agree it's better not to mix different event triggers with one another. That's what I ended up doing anyway.
0
All Courses

From novice to tech pro — start learning today.