title: I can't get my web page to navigate trhorugh URLs located in selection list in JScript
body: <p>I have a JavaScript homework assignment that needs to navigate to a selected URL located in a selection list. I thought I had this one down but am stuck. I will list the directions for the assignment so somebody might be able to pinpoint my mistake(s) according to the lesson plan. Any help would be greatly appreciated! </p>
  
  <p>Create the init() function. Within this function do the following:
  a) Create a variable named allSelect that references all of the selection elements in
  the document.
  b) For each item within the allSelect object collection, add an onchange event
  handler that runs the loadLink() function when the selection list changes.</p>
  
  <p>Create the loadLink() function. The purpose of this function is to cause the browser
  to load a URL from a selection list. Add the following commands to the function:
  a) Create a variable named sIndex that points to the index of the selected option in
  the current selection list. (Hint: Use the this keyword to reference the current
  selection list.)
  b) Web pages can be loaded using the command
  location.href = url;
  where url is the URL of theWeb page. Enter this command into the function using the
  value of the selected option from the selection list as the value of url. (Hint: Use the
  sIndex variable to point to the selected option from the current selection list.)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;!-- 
     New Perspectives on HTML, XHTML and DHTML 4th Edition
     Tutorial 14
     Case Problem 1
  
     Monroe Public Library
     Author: Collin Klopstein
     Date: November 27, 2013  
  
     Filename:         mpl.htm
     Supporting files: links.js, mplstyles.css. mpl.jpg
  --&gt;
     &lt;title&gt;Monroe Public Library List of Government Sites&lt;/title&gt;
     &lt;link href="mplstyles.css" rel="stylesheet" type="text/css" /&gt;
  
     &lt;script type="text/javascript"&gt;
      window.onload = init;
  
      function init() {
          var allSelect = document.getElementsByTagName("*");
  
          for (var i = 0; i &lt; allSelect.length; i++) {
              if (allSelect[i].classname == "optionLinks") allSelect.push(allSelect[i]) {
              allSelect[i].onchange = loadLink;
              }
          }
      }
  
      function loadLink() {
          var sIndex = this.selectedIndex;
          location.href = this.options[sIndex].value;
      }
      &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;p id="head"&gt;
     &lt;img src="mpl.jpg" alt="Monroe Public Library" /&gt;
  &lt;/p&gt;
  
  &lt;div id="links"&gt;
     &lt;span&gt;Quick Links&lt;/span&gt;
     &lt;a href="#"&gt;Home Page&lt;/a&gt;
     &lt;a href="#"&gt;Online Catalog&lt;/a&gt;
     &lt;a href="#"&gt;Friends of MPL&lt;/a&gt;
     &lt;a href="#"&gt;New Books and Other Good Reading&lt;/a&gt;
     &lt;a href="#"&gt;Illinois Virtual Library&lt;/a&gt;
     &lt;a href="#"&gt;Internet Public Library&lt;/a&gt;
     &lt;a href="#"&gt;Services and Collection&lt;/a&gt;
     &lt;a href="#"&gt;Adult Programs&lt;/a&gt;
     &lt;a href="#"&gt;Teen Central&lt;/a&gt;
     &lt;a href="#"&gt;Children's Room&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;div id="main"&gt;
  &lt;h2&gt;Government Sites on the Web&lt;/h2&gt;
  
  &lt;p&gt;Select a site from one of the drop-down lists below.&lt;/p&gt;
  &lt;table&gt;
     &lt;tr&gt;&lt;td&gt;Executive Branch&lt;/td&gt;
         &lt;td&gt;&lt;select name="executive" id="executive" class="optionLinks"&gt;
             &lt;option value="#"&gt;Select a Web site&lt;/option&gt;
             &lt;option value="http://www.whitehouse.gov"&gt;The White House&lt;/option&gt;
             &lt;option value="http://www.usda.gov"&gt;Department of Agriculture&lt;/option&gt;
             &lt;option value="http://www.doc.gov"&gt;Department of Commerce&lt;/option&gt;
             &lt;option value="http://www.defenselink.mil"&gt;Department of Defense&lt;/option&gt;
             &lt;option value="http://www.ed.gov"&gt;Department of Education&lt;/option&gt;
             &lt;option value="http://www.energy.gov"&gt;Department of Energy&lt;/option&gt;
             &lt;option value="http://www.os.dhhs.gov"&gt;Department of Health and Human Services&lt;/option&gt;
             &lt;option value="http://www.whitehouse.gov/homeland"&gt;Department of Homeland Security&lt;/option&gt;
             &lt;option value="http://www.hud.gov"&gt;Department of Housing and Urban Development&lt;/option&gt;
             &lt;option value="http://www.doi.gov"&gt;Department of the Interior&lt;/option&gt;
             &lt;option value="http://www.usdoj.gov"&gt;Department of Justice&lt;/option&gt;
             &lt;option value="http://www.dol.gov"&gt;Department of Labor&lt;/option&gt;
             &lt;option value="http://www.state.gov"&gt;Department of State&lt;/option&gt;
             &lt;option value="http://www.ustreas.gov"&gt;Department of the Treasury&lt;/option&gt;
             &lt;/select&gt;
         &lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;&lt;td&gt;Legislative Branch&lt;/td&gt;
         &lt;td&gt;&lt;select name="legislative" id="legislative" class="optionLinks"&gt;
             &lt;option value="#"&gt;Select a Web site&lt;/option&gt;
             &lt;option value="http://www.house.gov"&gt;House Web Site&lt;/option&gt;
             &lt;option value="http://www.house.gov/house/MemberWWW.shtml"&gt;Representatives' Web Sites&lt;/option&gt;
             &lt;option value="http://clerk.house.gov/"&gt;Clerk of the House&lt;/option&gt;
             &lt;option value="http://www.gpoaccess.gov/cdirectory/index.html"&gt;Congressional Directory&lt;/option&gt;
             &lt;option value="http://www.senate.gov"&gt;Senate Web Site&lt;/option&gt;
             &lt;option value="http://www.senate.gov/general/contact_information/senators_cfm.cfm"&gt;Senators' Web Sites&lt;/option&gt;
             &lt;option value="http://www.senate.gov/artandhistory/history/common/generic/Senate_Historical_Office.htm"&gt;Senate Historic Office&lt;/option&gt;
             &lt;option value="http://www.cq.com"&gt;Congressional Quarterly&lt;/option&gt;
             &lt;option value="http://www.loc.gov/"&gt;Library of Congress&lt;/option&gt;
             &lt;option value="http://www.gao.gov/"&gt;Government Accountability Office&lt;/option&gt;
             &lt;option value="http://www.cbo.gov/"&gt;Congressional Budget Office&lt;/option&gt;
             &lt;option value="http://www.gpoaccess.gov/"&gt;Government Printing Office&lt;/option&gt;
             &lt;option value="http://thomas.loc.gov/home/legbranch/otherleg.html#govpub"&gt;Government Records and Publications&lt;/option&gt;
             &lt;/select&gt;
         &lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;&lt;td&gt;Judicial Branch&lt;/td&gt;
         &lt;td&gt;&lt;select name="judicial" id="judicial" class="optionLinks"&gt;
             &lt;option value="#"&gt;Select a Web site&lt;/option&gt;
             &lt;option value="http://www.uscourts.gov"&gt;U.S. Courts&lt;/option&gt;
             &lt;option value="http://www.uscourts.gov/supremecourt.html"&gt;U.S. Supreme Court&lt;/option&gt;
             &lt;option value="http://www.uscourts.gov/courtsofappeals.html"&gt;U.S. Courts of Appeals&lt;/option&gt;
             &lt;option value="http://www.uscourts.gov/districtcourts.html"&gt;U.S. District Courts&lt;/option&gt;
             &lt;/select&gt;
         &lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;&lt;td&gt;State Governments&lt;/td&gt;
         &lt;td&gt;&lt;select name="state" id="state" class="optionLinks"&gt;
             &lt;option value="#"&gt;Select a Web site&lt;/option&gt;
             &lt;option value="http://www.statelocalgov.net/index.cfm"&gt;State and Local Government on the Net&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/al-gov.html"&gt;Alabama&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ak-gov.html"&gt;Alaska&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/az-gov.html"&gt;Arizona&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ar-gov.html"&gt;Arkansas&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ca-gov.html"&gt;California&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/co-gov.html"&gt;Colorado&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ct-gov.html"&gt;Connecticut&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/de-gov.html"&gt;Delaware&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/dc-gov.html"&gt;District of Columbia&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/fl-gov.html"&gt;Florida&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ga-gov.html"&gt;Georgia&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/hi-gov.html"&gt;Hawaii&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/id-gov.html"&gt;Idaho&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/il-gov.html"&gt;Illinois&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/in-gov.html"&gt;Indiana&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ia-gov.html"&gt;Iowa&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ks-gov.html"&gt;Kansas&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ky-gov.html"&gt;Kentucky&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/la-gov.html"&gt;Louisana&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/me-gov.html"&gt;Maine&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/md-gov.html"&gt;Maryland&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ma-gov.html"&gt;Massachusetts&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/mi-gov.html"&gt;Michigan&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/mn-gov.html"&gt;Minnesota&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ms-gov.html"&gt;Mississippi&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/mo-gov.html"&gt;Missouri&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/mn-gov.html"&gt;Montana&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ne-gov.html"&gt;Nebraska&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/nv-gov.html"&gt;Nevada&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/nh-gov.html"&gt;New Hampshire&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/nj-gov.html"&gt;New Jersey&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/nm-gov.html"&gt;New Mexico&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ny-gov.html"&gt;New York&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/nc-gov.html"&gt;North Carolina&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/nd-gov.html"&gt;North Dakota&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/oh-gov.html"&gt;Ohio&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ok-gov.html"&gt;Oklahoma&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/or-gov.html"&gt;Oregon&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/pa-gov.html"&gt;Pennsylvania&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ri-gov.html"&gt;Rhode Island&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/sc-gov.html"&gt;South Carolina&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/sd-gov.html"&gt;South Dakota&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/tn-gov.html"&gt;Tennessee&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/tx-gov.html"&gt;Texas&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/ut-gov.html"&gt;Utah&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/vt-gov.html"&gt;Vermont&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/va-gov.html"&gt;Virginia&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/wa-gov.html"&gt;Washington&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/wv-gov.html"&gt;West Virginia&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/wi-gov.html"&gt;Wisconsin&lt;/option&gt;
             &lt;option value="http://www.loc.gov/global/state/wy-gov.html"&gt;Wyoming&lt;/option&gt;
             &lt;/select&gt;
         &lt;/td&gt;
     &lt;/tr&gt;
  &lt;/table&gt;
  &lt;address&gt;
     &lt;b&gt;Monroe Public Library&lt;/b&gt;
     580 Main Street, Monroe, OH &amp;nbsp;&amp;nbsp;45050
     &lt;b&gt;Phone&lt;/b&gt; (513) 555-0211  
     &lt;b&gt;Fax&lt;/b&gt; (513) 555-0241
  &lt;/address&gt;
  &lt;/div&gt;       
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>