/    Sign up×
Community /Pin to ProfileBookmark

Passing variable from page1,page2, page3 via URL

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>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@micheleauthorMar 03.2003 — 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.
Copy linkTweet thisAlerts:
@micheleauthorMar 07.2003 — Thanks so much! That worked!!
×

Success!

Help @michele spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...