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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.