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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passed values from HTML to HTML

    I need to take a parameter that is coming into a page and pass it along, in a hidden field, when the form is submitted. Can someone please let me know if this is the correct way of doing this? Thanks in advance for any help.

    <script language="JavaScript">
    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->
    <!-- Begin
    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();
    // End -->
    </script>

    <script language="JavaScript">
    <!-- Begin
    provider = unescape(params["provider"]);
    document.write('<input type="hidden" size="20" name="provider" value="'+ provider +'">');
    // End -->
    </script>

  • #2
    JUD
    JUD is offline
    New Coder
    Join Date
    Jul 2005
    Location
    I'm right here
    Posts
    92
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Yes, that would work.

    Here's another way to do it using loaction.search to get the query string

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    /*<![CDATA[*/
    	function getParams(){
    		var idx = location.search.replace("?", "");
    		var params = new Array();
    		
    		if(idx != -1){
    			var pairs = idx.split("&");
    			for(var i = 0; i < pairs.length; i++){
    				var nameVal = pairs[i].split("=");
    				params[nameVal[0]] = nameVal[1];
    			}
    		}
    		return params;
    	}
    	
    	var params = getParams();
    /*]]>*/
    </script>
    </head>
    
    <body>
    <script type="text/javascript">
    /*<!CDATA[*/
    	document.write('<input type="hidden" name="provider" value="' + params["provider"] + '">');
    /*]]>*/
    </script>
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks JUD,

    I didn't have a way of testing, form being sent to server that is unavailable, but I still needed to build the pages.


  •  

    Posting Permissions

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