views:

36

answers:

2

There is an 'onchange' event, using inline javascript on a dropdown list which I have no control over.

In the onready event, if I bind another onchange event, which one will fire first? And will this be a gauranteed order?

I want mine to fire AFTER the inline js onchange event.

+2  A: 

In most implementations, events fire in the order that they are specified. This order is not guaranteed, though. The ECMAScript spec does not define this.

elusive
A: 

Is it possible you can replace the initial onchange methdod.

var select = document.getElementById('myElementId');
var proxy = select.onchange;
select.onchange=null;
var wrapper = function (e) {
  if (!window.event) { 
   // for compatibility on non-IE browsers where event may be used inline
   // untested
   window.event = e; 
  }
  // executes the original handler in the scope of the original element
  proxy.apply(select); 
  // new function you want to run
  myFn();
};
if (select.addEventListener) {
  select.addEventListener('change', wrapper ,false);
}
else {
  select.attachEvent('onchange', wrapper);
}

I have this working as a proof of concept. What does the original element markup look like? Depending on what variables are referenced in the original onchange it may or may not fit your problem.

live demo: http://jsbin.com/ufohu4

lincolnk