Say I have variables that I acquire in one html page, such as a UserName or a url or something. And in another html page I have input boxes for these variables and I want to autocomplete them by sending the data from the first html page to the input boxes in the second one. Can anyone indicate to me how I can achieve this?
-
possibly a duplicate of http://stackoverflow.com/questions/216536/what-is-the-best-practice-for-passing-variables-from-one-html-page-to-another?rq=1 – Saurabh Kumar Jul 05 '12 at 10:19
-
in PHP or in Javascript? – akhil Jul 05 '12 at 10:20
4 Answers
You should use $_SESSION variable in php. OR you can use sessionStorage of javascript.

- 310,957
- 84
- 592
- 636
Use JavaScript to create the equivalent collection for use by other JS code:
Code:
<script type="text/javascript">
var querystring = [ ];
var qs = location.search;
if ( qs.length > 1 )
{
qs = qs.substring(1); // skip past the ?
var pairs = qs.split( /\&/g ); // get all the name=value pairst
for ( var p = 0; p < pairs.length )
{
var pair = pairs[p];
querystring[ pair[0] ] = unescape( pair[1].replace(/\+/g," ");
}
}
</script>
Then, anyplace in your page where in ASP code you might use
Code:
var foo = Request.QueryString("foo");
you instead simply do
Code:
var foo = querystring["foo"];
CAUTION: "foo" will be case sensitive, unlike in ASP. If you wish, you could replace Code:
querystring[ pair[0] ] = unescape( pair[1].replace(/\+/g," ");
with
querystring[ pair[0].toLowerCase() ] = unescape( pair[1].replace(/\+/g," ");
and then always use lower case names ("foo" in place of "Foo" or "FOO") when finding values.
Untested, though I have used this same code before. If there's a goof, it's just a typo.

- 1,202
- 3
- 21
- 43
You can use JQuery for that. Assuming you are not using any server side code.
Pass the value as a param to the next page.
Like myurl?param=xyz
Then you can get the value in the next page like this,
See this answer and sourcecode
var xyz = jQuery.url.param("param_in_url");

- 1
- 1

- 8,171
- 3
- 26
- 47
-
Can you elaborate on this? So if I go - var xyz = "matt@example.com"; var url = 'http://caregap2.appspot.com/myurl?param=xyz'; location.href = url; Then in my next page : var xyz = jQuery.url.param("http://caregap2.appspot.com/myurl?param=xyz"); Is that correct? – user1501171 Jul 05 '12 at 11:08
-
I think it was a typo. It should be like var url = 'caregap2.appspot.com/myurl?param='+xyz; – Subir Kumar Sao Jul 05 '12 at 11:11
For this you can use php session .store that variable in session and get them in any page.or if you are calling that page from the page where u have values say username call like
<a href="nextpage.php?username='ur value'">next page </a>

- 520
- 4
- 15