Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Adding Multiple Event Listeners

Charles Harpke
Charles Harpke
33,986 Points

We've got a select box that's used to navigate to a new page on the "change" event and record some analytics. We want tw

Unfortunately, I'm not able to visualize the task at hand... All I know is that I am using the addEventListener() method...

What change method am I employing on the the right side of lines 14 and 15, on the other side of the event listen?

//Select select box
var navigationSelect = document.getElementById("nav");

//Navigate to URL when select box is changed
var navigateToValue = function() {
  window.location = this.value;
}

//Send analytics data
var sendAnalytics = function() {
  //Placeholder  
}

navigationSelect.addEventListener = navigateToValue;
navigationSelect.addEventListener = sendAnalytics

2 Answers

Iago Wandalsen Prates
Iago Wandalsen Prates
21,699 Points

You're using addEventListener wrong. addEventListener is a method, that takes a list of arguments, and add them to the eventList. It's not the eventList itself. Correct way is .addEventListener(eventToBeAdded)

Charles Harpke
Charles Harpke
33,986 Points

Gotcha...thank you:

navigationSelect.addEventListener ("change", navigateToValue );
navigationSelect.addEventListener ("change", sendAnalytics);