Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Yohan Aton
Yohan Aton
1,738 Points

Drawing a blank on the solution...

Hi, thanks for taking a sec. If you can post the solution, I believe I can see it and understand it.

Thank You!!!

//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.change.addEventListener() = navigateToValue;
navigationSelect.change.addEventListener() = sendAnalytics;
Steven Parker
Steven Parker
216,164 Points

Remember to select "best answer". :)

2 Answers

Steven Parker
Steven Parker
216,164 Points

SPOILER ALERT

You had the right idea to create additional event "listeners", each of which will invoke a function when the event occurs. But instead of using assignments the call takes two arguments, first the type of event to respond to, and the next is the function to invoke.

So change the last two lines to:

navigationSelect.addEventListener("change", navigateToValue);
navigationSelect.addEventListener("change", sendAnalytics);
Mark Miller
Mark Miller
45,831 Points

How did you know of the event called "change" for the select menu with the id "nav"? I understand that "change" represents the event when a visitor selects an option from the select menu, but the only place where I see the word "change" representing this event is here in the Treehouse community forum. I am unable to find the word "change" representing an event, for the selection of an option from a menu, anywhere in the Mozilla Developer Network documentation for the addEventListener. Now I could pass this quiz, but I did not know why it was "change" representing the event. So, in the future, I am not able to find the names of the events that could trigger the listeners.