Click to See Complete Forum and Search --> : Passing variable from page1,page2, page3 via URL


michele
03-01-2003, 10:21 PM
How do I pass the value of variables into my next webpage's URL? In the sample code below I'd like to pass the value of the variables "argname" and "value" retrieved from the QueryString into the URL of my next webpage. I'm using a hidden form and I'd like to substitute the value of the variable 'argname' for the value field in the hidden form. Or maybe someone knows of a better way. Thanks!

(<input type="hidden" name="fruits" value="argname">)


Here's some sample code:
===================
<script language="JavaScript" type="text/JavaScript"><!--

var argname = "";
var value = "";
var pairs = "";

QueryString.keys = new Array();
QueryString.values = new Array();
QueryString_Parse();

function QueryString(key){
var value = null;
for (var i=0;i<QueryString.keys.length;i++){
if (QueryString.keys==key){
value = QueryString.values;
break;
}
}
return value;
}


function QueryString_Parse(){
var query = window.location.search.substring(1);
pairs = query.split("&");

for (var i=0;i<(pairs.length-1);i++){
var pos = pairs.indexOf('=');
if (pos >= 0)
{
argname = pairs.substring(0,pos);
value = pairs.substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}


//-->
</script>
</head>
<
.....
.....
.....
<p>My WebPage:</p>
<form action="http://mylocalhostname/samplehost/getfruits.shtm" method="get" name="form3" id="form3">
<p>
<select name="fruit" size="1" id="fruit">
<option value="hr" selected>Head Revision</option>
<option value="orange">orange</option>
<option value="apple">apple</option>
</select>
</p>
<p>
<input type="hidden" name="fruits" value="argname">
<input type="submit" name="Submit" value="Next"></form>
</p>
</form>

michele
03-03-2003, 11:21 AM
Thank you for your help Dave, but I am still puzzled by what you mean. I'm very new to Javascript & HTML and I'm trying to learn as much as possible. When you say "dynamically build the hidden fields" I'm not sure what you mean. Is there anyway that you could explain that further. I'd really appreciate it if you could. Thank you so much.

michele
03-06-2003, 08:11 PM
Thanks so much! That worked!!