I am trying to pull a variable from a url and populate a hidden variable in my form using jquery.
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!
My url is: http://www.mysite.com?ad=cl55
The script I am using to pull the variable from the query string:
<script type="text/javascript">
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
jQuery(document).ready(function(){
var adtest = getURLParameter('ad');
$('input[name=meta_adtracking]').val(adtest);
});
</script>
My form code is:
<form accept-charset="utf-8" action="https://app.getresponse.com/add_contact_webform.html" method="GET">
...
<input type="hidden" id="adtrack1" name="meta_adtracking" value="" />
...
</form>
Thanks in advance!