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 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript within forms - duplicating values to create a query string in the retURL

    Hello,

    I was trying to do the following...
    I would like to grab the value that someone has typed into the "first_name" text input field and somehow attach it on the end of the "retURL" hidden field, so that the URL would look like this: http://www.name.com/ty.php?first_name=michael"

    In other words, I would like to find a way to create a script that will create a "querystring" based on the form values. I then can populate/personalize the "ty.php" page.

    I am using the following code for the form:
    <form action="http://www.salesforce.com/servlet......" method="POST" />
    <input type="hidden" name="oid" value="........." />
    <input type="hidden" name="retURL" value="www.name.com/ty.php" />
    <input maxlength="40" type="text" id="first_name" size="20" name="first_name" class="req" value="" />
    <input type="submit" name="scs" id="submit" value="Submit">

    Thanks guys.

    Michael

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,461
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Code:
    var allFormsData=[];
    
    for (var z=0; z< document.forms.length; z++){
    var inputs = document.forms[z].elements;
    var mx= inputs.length;
    var qs=[];
    
    for(var i=0; i<mx; i++){
    if(inputs[i].name && inputs[i].value || inputs[i].checked )qs[qs.length]="&"+escape(inputs[i].name)+"="+ escape(inputs[i].checked || inputs[i].value);
    var out=qs.join("").substr(1)
    }
    allFormsData[z]= out
    }//next
    
    
    alert(  allFormsData.join("\n"))
    /* at coding forums (some numbers slightly changed)
    
    wysiwyg=0&styleid=0&signature=true&quickreply=1&fromquickreply=1&do=postreply&t=129444&p=who&#37;20cares&parseurl=1&loggedinuser=546546&sbutton=Post%20Quick%20Reply&preview=Go%20Advanced
    do=process&searchthreadid=129444
    s=3e191e52da&t=129444&pp=15&page=1&vote=5
    f=2
    f=2
    */
    Last edited by rnd me; 12-10-2007 at 08:25 PM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    <input type="hidden" name="retURL" value="www.name.com/ty.php" />
    <input maxlength="40" type="text" id="first_name" size="20" name="first_name" class="req" value="" onchange="addName(this)">

    <script type = "text/javascript">
    function addName(which) {
    newUrl = retURL.value + "?first_name=" + which.value;
    alert (newUrl); // delete after testing
    }

    </script>


    But surely you have more than one Michael, Tom, Bill etc.????

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Philip M - it doesn't seem to work...

    Hey Philip...

    I can see the logice, but it doesn't seem to work.

    Is there something I need to add into the "retURL" value to add the string on the back?

    Thanks.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by this_end_up View Post
    Hey Philip...

    I can see the logice, but it doesn't seem to work.

    Is there something I need to add into the "retURL" value to add the string on the back?

    Thanks.
    It works fine for me!

    When I enter philip I get the alert

    www.name.com/ty.php?first_name=philip

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Philip,

    I see how it works...that is sort of what I want to do.

    But just for kicks...this is what I want to do.

    I would like to have a form with about 5 fields (first_name, last_name, title, phone, company), and when you hit the submit button, the forms action would write it to salesforce's database and the "<input type="hidden" name="retURL" value="" />" value would be generated by something similar to what you created...but using "document.write" or "return (newURL)"

    Anyyways, let me know if you can help me out.

    Michael

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Not sure that I understand your problem. As I understand it you want the value of retURL to have the name added to the string.

    <input type="hidden" name="retURL" value="www.name.com/ty.php" />
    <input maxlength="40" type="text" id="first_name" size="20" name="first_name" class="req" value="" onchange="addName(this)">

    <script type = "text/javascript">

    function addName(which) {
    newUrl = retURL.value + "?first_name=" + which.value;
    alert ("newUrl = " + newUrl); // delete after testing
    retURL.value = newUrl;
    alert ("retURL = " + retURL.value); // delete after testing
    }

    </script>


  •  

    Posting Permissions

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