...

View Full Version : passed values from HTML to HTML



Joe9999999
05-24-2006, 03:47 PM
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>

JUD
05-24-2006, 06:09 PM
Yes, that would work.

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



<!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>

Joe9999999
05-24-2006, 07:40 PM
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. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum