How to register multiple external listeners to the same selection in d3?

You can add a namespace to the event name like:

d3.select("#timebasis")
    .on("change.sp", listenersp)
    .on("change.bt", listenerbt);

See: https://github.com/mbostock/d3/wiki/Selections#wiki-on

If an event listener was already registered for the same type on the
selected element, the existing listener is removed before the new
listener is added. To register multiple listeners for the same event
type, the type may be followed by an optional namespace, such as
“click.foo” and “click.bar”. To remove a listener, pass null as the
listener.

The functions are being passed the current datum d and index i, with the this context as the current DOM element. It looks like your two function expect the DOM element as argument? In that case it would look like:

d3.select("#timebasis")
    .on("change.sp", function() { selectIndexSp(this); })
    .on("change.bt", function() { selectIndexBt(this); });

Leave a Comment