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

What am I doing wrong with the addEventListener()?

Can anyone please look my code and tell me what I'm doing wrong with this challenge.

app.js
//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(click,'change') = navigateToValue ;
navigationSelect.addEventListener (click,'change') = sendAnalytics  ;
index.html
<!DOCTYPE html>
<html>
  <body>
    <select id="nav">
      <option value="index.html">Home</option>
      <option value="about.html">About</option>
    </select>
    <h1>Home</h1>
    <script src="app.js"></script>
  </body>
</html>
about.html
<!DOCTYPE html>
<html>
  <body>
    <select id="nav">
      <option value="index.html">Home</option>
      <option value="about.html">About</option>
    </select>
    <h1>About</h1>
    <script src="app.js"></script>
  </body>
</html>

2 Answers

Jeremy Faith
PLUS
Jeremy Faith
Courses Plus Student 56,696 Points

You added the addEventListener but did not format it correctly. Your code should look like this.

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

Syntax

target.addEventListener(type, listener[, useCapture]);

type

A string representing the event type to listen for.

listener

The object that receives a notification when an event of the specified type occurs. This must be an object implementing the EventListener interface, or simply a JavaScript function.

Alright, thank you for your help.