I am trying to capture a referral ID from a URL into a web form as a hidden field. For example the landing URL would be: http://www.yoursite.com/inquiry.html?a_aid=38561bce I need the form on that page to capture something like: <input name="lead_source" value="38561bce" type="hidden"> I have tried this Javascript code, but it just doesnt want to do anything: <script> function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); if (pair[0] == variable) { return pair[1]; } } } </script> <script type="text/javascript" language="JavaScript"><!-- document.write('<input '); document.write(' type="hidden" '); document.write(' name="lead_source" '); document.write(' value="' + getQueryVariable("a_aid") + '">'); //--></script> HTML: Does anybody have any other ideas? Thanks in advance.
Also, I dont need this to be in Javascript, it can use PHP or whatever, I just need it to work. Thanks; it's driving me crazy.
This should output what you are looking for: <?php echo "<input type=\"hidden\" name=\"lead_source\" value=\"".addslashes($_GET['a_aid'])."\">"; ?> PHP:
<input type="hidden" name="lead_source" value="<%=request.querystring("a_aid")%>" /> Code (Classic ASP): Above is classic asp but would work in .net but isnt the preferred methodology for .net