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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!