I'm struggling with this JavaScript, validator keeps telling me it's wrong. How do I solve this?
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 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;
}
}
}
)
Accounting
ISBN: 978-0324188004
21st Edition
Authors: Carl s. warren, James m. reeve, Philip e. fess