title: How to set a value for a dropdown list with a value from URL by clicking on a link
body: <p>I'm trying to set a value for a dropdown list by clicking on a link(links to the same page), and the value that i want to set for the select is in the link.<br>
  I tried to do it this way, but because it is messed up it didn't work.<br>
  Here's the code i used:  </p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;select id="select"&gt;
  &lt;option value="one"&gt;Pen&lt;/option&gt;
  &lt;option value="two"&gt;Paper&lt;/option&gt;
  &lt;option value="three"&gt;Book&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;a class="link1" href="page.php?cc=three"&gt;Set select value&lt;/a&gt;
  
  &lt;script&gt; 
      function $_GET(param) {
          var vars = {};
              window.location.href.replace( location.hash, '' ).replace( 
                  /[?&amp;]+([^=&amp;]+)=?([^&amp;]*)?/gi, // regexp
                  function( m, key, value ) { // callback
                  vars[key] = value !== undefined ? value : '';
                  }
              );
  
          if ( param ) {
              return vars[param] ? vars[param] : null;    
          }
              return vars;
      }
  
      var cc = $_GET('cc');
  
      var elmnt = document.getElementsByClassName('link1'),
          selectClasse = document.getElementById('select');
  
              function setSelect () {
              for (var i = 0; i &lt; elmnt.length; i++) {
                  elmnt[i].onclick = function () {
  
                  selectClasse.value = cc;
                      }
          window.history.pushState('Form', 'My form', this.getAttribute("href"));
          return false;
          };
      }
  }
  setSelect ();
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;  
  </code></pre>
  
  <p>Any help would be much appreciated.</p>