Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting

Authors: Carl s. warren, James m. reeve, Philip e. fess

21st Edition

978-0324400205, 324225016, 324188005, 324400209, 9780324225013, 978-0324188004

More Books

Students also viewed these Programming questions