Question
I'm struggling with this JavaScript, validator keeps telling me it's wrong. How do I solve this? Instructions: Use event listener for the load
I'm struggling with this JavaScript, validator keeps telling me it's wrong. How do I solve this?
Instructions:
Use event listener for the load event that runs an anonymous function. Within the anonymous function, create the allSelect variable referencing all select elements nested within the govLinks form. Loop through the allSelect object collection and for each selection list in the collection create an anonymous function for the onchange event. Within this anonymous function, use the href property of the location object to change the page shown in the browser window to the value of the target of the event object that initiated the onchange event. Document your commands with JavaScript commenJS
JS File:
"use strict";
/*
New Perspectives on HTML5, CSS3, and JavaScript 6th Edition
Tutorial 13
Case Problem 1
Author:
Date: 08/08/2022
Filename: mpl_links.js
*/
window.addEventListener ("load", function() {
var allSelect = document.getElementById("govtLinks").querySelectorAll("select");
for (var i = 0; i < allSelect.length; i++) {
allSelect[i].onchange = function(e) {
location.href = e.target.value;
}
}
}
)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started