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 trialRobert Booth
2,290 PointsNeed help with this because I am completely lost.
I am unsure what to choose for this and would really like some help.
//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.onchange = navigateToValue;
navigationSelect.onchange = sendAnalytics;
<!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>
<!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>
1 Answer
Ken Alger
Treehouse TeacherRobert;
There is a JavaScript method to which you can pass arguments called addEventListener()
and you could do something like:
navigationSelect.addEventListener("change", navigateToValue);
Post back if you are still stuck.
Happy coding,
Ken