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
Stu Cowley
26,287 PointsHelp with Final Code Challenge For "Interactive Web Pages with JavaScrip"
Hey guys,
I have been scratching my head over this for way too long. I know I should have gotten this correct by now.
The task is asking
"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 two event handlers to fire, fix lines 14 and 15 so that both of the handlers trigger on "change" rather than just the last function assigned to onchange."
I have tried the following code but I am completely stumped for the correct answer:
//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
}
// ***MY CODE***
navigationSelect.addEventListener = ("change", navigateToValue);
navigationSelect.addEventListener = ("change", sendAnalytics);
Maybe Andrew Chalkley could shed some light on this for me ; )
Thanking you all in advance
Stu : )
3 Answers
Dave McFarland
Treehouse TeacherHi Stu Cowley
The addEventListener() is a method that you pass arguments to. You don't use the = sign when using addEventListener(). Like this:
navigationSelect.addEventListener("change", navigateToValue);
Stu Cowley
26,287 PointsYou're a champion Dave McFarland!
Thank you so much, that = sign always gets me haha.
Thanks again,
Stu : )
Maureen O'Neal
12,930 PointsYes, thank you, I was a little stuck, with the Onchange!