Capturing a referral ID in a web form as a hidden field

Discussion in 'Programming' started by DreamWeb, Jan 16, 2008.

  1. #1
    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.
     
    DreamWeb, Jan 16, 2008 IP
  2. DreamWeb

    DreamWeb Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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.
     
    DreamWeb, Jan 16, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    This should output what you are looking for:

    <?php
    echo "<input type=\"hidden\" name=\"lead_source\" value=\"".addslashes($_GET['a_aid'])."\">";
    ?>
    PHP:
     
    jayshah, Jan 16, 2008 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <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
     
    AstarothSolutions, Jan 16, 2008 IP