title: Passing an URL parameter to a href link using Javascript
body: <p>I have the following code working to pass a URL parameter to a form tag:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    function getQueryVariable(variable) { 
   var query = window.location.search.substring(1); 
   var vars = query.split("&amp;"); 
   for (var i=0;i&lt;vars.length;i++) { 
   var pair = vars[i].split("="); 
   if (pair[0] == variable) { 
     return pair[1]; 
      }
    }
  }
   function onLoad() {
  var value = getQueryVariable("ID");
  var e = document.getElementById('your-field');
  e.value = value;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>And...</p>
  
  <pre><code>&lt;body onload="onLoad()"&gt;
   &lt;!-- your form and hidden field goes here --&gt;
   &lt;input type="hidden" name="your-field" id="your-field" /&gt;
  </code></pre>
  
  <p>How can I pass the same value to an HTML link so that the end result would be:</p>
  
  <pre><code>&lt;a href="http://www.mysite.com?source=[ID]" &gt;
  </code></pre>
  
  <p>Where [ID] is the whatever piece of code that is needed to add the parameter to the link?</p>
  
  <p>Thanks in advance.</p>