Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pass parameters to HTML form via URL

    I am a newbie. I want to pass two parameters to an HTML form on my site, like this:-

    http://usbdial.com/userinfo.htm?emai...t.com&cid=1234


    This is what I've done so far:
    • Created a simple HTML form.
    • Added some Javascript, using script found on the internet.
    • Ran the form at
    http://usbdial.com/userinfo.htm?email=test@test.com&cid=1234

    It does not pass the parameters - it shows that the fields are undefined.

    Can anyone see what I've done wrong?

    Also, when you view the page source, function SymError() appears twice, even although in my source it appears only once. Any idea why it appears twice?

    Any guidance will be welcome.

  • #2
    New Coder TripperTreats's Avatar
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your only problem is this:

    Code:
    pvName = unescape(params["uname"]);
    document.myForm.email.value = pvName;
    
    pvName = unescape(params["pass"]);
    document.myForm.cid.value = pvName;
    Just change "uname" to "email" and "pass" to "cid". Also, for the life of me I can't figure out why this isn't causing an error:
    Code:
    function getParams() {
      var idx = document.URL.indexOf('?');
      var params = new Array();
        
      if (idx != -1) {
        var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
        for (var i=0; i<pairs.length; i++) {
          nameVal = pairs[i].split('=');
          params[nameVal[0]] = nameVal[1];
        }
      }
    return params;
    }
    params = getParams();
    "params" is being assigned a value before being declared a variable.
    Also, inside the function, "params" should be an object, not an array.
    At any rate, I tested it, and you should replace it with this:

    Code:
    function getParams() {
      var idx = document.URL.indexOf('?');
      var tempParams = new Object();
      if (idx != -1) {
        var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
        for (var i=0; i<pairs.length; i++) {
          nameVal = pairs[i].split('=');
          tempParams[nameVal[0]] = nameVal[1];
        }
      }
    return tempParams;
    }
    var params = getParams();
    Psychedelic digital art at www.trippertreats.com.

    "And in the end, the love you take
    is equal to the love you make
    ."

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks TripperTreats. Your suggestions fixed the issue.

    Another question if I may:

    When I type into the bowser:
    http://usbdial.com/userinfo.htm?emai...t.com&cid=1234
    then the fields show correctly with the parameters in the fields.

    However typing this:
    http://usbdial.com/userinfo.htm
    shows the fields as "undefined".

    If I don't pass any parameters in the URL, do you know how can I get the fields to be blank rather that filled with "undefined"?

  • #4
    New Coder TripperTreats's Avatar
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No problem. Replace your source code with this (I've repeated the whole thing so you can just copy and paste):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta name="generator" content="HTML Tidy for Windows (vers 1 June 2005), see www.w3.org">
    <meta http-equiv="Content-Language" content="en-au">
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>User info</title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function SymError()
    {
      return true;
    }
    
    window.onerror = SymError;
    
    var SymRealWinOpen = window.open;
    
    function SymWinOpen(url, name, attributes)
    {
      return (new Object());
    }
    
    window.open = SymWinOpen;
    
    //-->
    </script>
    <script language="JavaScript" type="text/javascript">
        
          <!-- Begin
    function getParams() {
      var idx = document.URL.indexOf('?');
      if (idx != -1) {
        var tempParams = new Object();
        var pairs = document.URL.substring(idx+1,document.URL.length).split('&');
        for (var i=0; i<pairs.length; i++) {
          nameVal = pairs[i].split('=');
          tempParams[nameVal[0]] = nameVal[1];
        }
        return tempParams;
      }
    }
    var params = getParams();
    
            
          //  End -->            
    </script>
    </head>
    <body>
    <form method="post" name="myForm" action="--WEBBOT-SELF--" id="myForm">
        <!--webbot bot="SaveResults" U-File="C:\TEST\Tutorial\Emails sent\_private\form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
        <p> Email:
            <input type="text" name="email" size="20">
        </p>
        <p> Account:
            <input type="text" name="cid" size="20">
        </p>
        <p>
            <input type="submit" value="Submit" name="B1">
            <input type="reset" value="Reset" name="B2">
        </p>
    </form>
    <script language="JavaScript" type="text/javascript">
       
          <!-- Begin
            pvName = unescape(params["email"]);
              if (pvName) document.myForm.email.value = pvName;            
    
            pvName = unescape(params["cid"]);
            if (pvName) document.myForm.cid.value = pvName;
          //  End -->
    
    </script>
    <script language="JavaScript" type="text/javascript">
    <!--
    var SymRealOnLoad;
    var SymRealOnUnload;
    
    function SymOnUnload()
    {
      window.open = SymWinOpen;
      if(SymRealOnUnload != null)
         SymRealOnUnload();
    }
    
    function SymOnLoad()
    {
      if(SymRealOnLoad != null)
         SymRealOnLoad();
      window.open = SymRealWinOpen;
      SymRealOnUnload = window.onunload;
      window.onunload = SymOnUnload;
    }
    
    SymRealOnLoad = window.onload;
    window.onload = SymOnLoad;
    
    //-->
    </script>
    </body>
    </html>
    Psychedelic digital art at www.trippertreats.com.

    "And in the end, the love you take
    is equal to the love you make
    ."

  • #5
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great! Excellent solution.

    Thanks Jason.

  • #6
    OXY
    OXY is offline
    New Coder
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Form Field Name Problem

    Hi,

    I found this script very useful and it does exactly what I need, however I“m facing the following problem I wonder you could help me with.

    My form was generated by a CRM application (SalesForce) and the custom fields are named such as 00N30000002PCO8.

    If I use this name in the script, it simply does not work.

    I believe it has to do with the name starting with a "0" (zero) or a number since the script works fine if I place the letter "a" at the start of the name such as: a00N30000002PCO8. But then, by changing the name, the field content is not captured by the CRM application.

    You can find the script NOT working because of this problem at:

    http://www.liveperson.com.br/temp/we...=mail@host.com

    A really appreciate any help/reply

    Best Regards,
    OXY


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •