title: I'm trying to pull a variable from a query string and use the value to populate a hidden variable in my form.
body: <p>I am trying to pull a variable from a url and populate a hidden variable in my form using jquery. </p>
  
  <p>I've been stuck on this for a few hours now, and I'm hoping someone better at jquery than me can help me out. I've found several solutions, but none of them seem to work for my code. I'm able to use an alert and confirm that I am pulling the 'ad' value from the string and assign to my 'adtest' variable, but nothing I try ever updates the 'meta_adtracking' hidden variable in my code. Any input is greatly appreciated!</p>
  
  <p>My url is:
  <a href="http://www.mysite.com?ad=cl55" rel="nofollow">http://www.mysite.com?ad=cl55</a></p>
  
  <p>The script I am using to pull the variable from the query string:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function getURLParameter(name) {
  return decodeURI(
      (RegExp(name + '=' + '(.+?)(&amp;|$)').exec(location.search)||[,null])[1]
      );
  }
  
  jQuery(document).ready(function(){
      var adtest = getURLParameter('ad');
      $('input[name=meta_adtracking]').val(adtest);
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>My form code is:</p>
  
  <pre><code>&lt;form accept-charset="utf-8" action="https://app.getresponse.com/add_contact_webform.html" method="GET"&gt;
  ...
      &lt;input type="hidden" id="adtrack1" name="meta_adtracking" value="" /&gt;
  ...
  &lt;/form&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>