DIGIT-ARC read-only archive · snapshot: July 23, 2026

javascript pass variable next page

8 posts · originally from https://geek.digit.in/community/threads/javascript-pass-variable-next-page.152484/

mohityadavx
mohityadavx Original post #1
Feb 9, 2012 at 11:59 AM
Well i am having a problem.

i have made a form and on clicking the submit button, javascript validation is done to check all fields are correctly filled or not. Now the problem is I want to use these entered variables so the only way remains is redirect the page to next page after clicking submit using "action = page.html" tag.

So how can i pass these variable to next page. I cant use PHP but javascript (Its kind of a constraint on me :( )

Well what i want is this site Kagzaat - Free Legal Online Documentation( www.kagzaat.com) to be in javascript instead of PHP . Please help.


if any other way exist please tell.
A
Feb 9, 2012 at 2:34 PM
Try Javascript Sessions or javascript cookies..
this might get you started
Cookie-less Session Variables in JavaScript » SitePoint
How to save session values in JavaScript - JavaScript / DHTML / AJAX | DaniWeb
RCuber
RCuber #3
Feb 9, 2012 at 3:54 PM
you can use two kinds of approach.
1. use global JS variables, include the variables in a JS file and refer those files in both the pages.
Ex: create test.js

Code:
// filename.js
var test1;
var test2;

then refer this JS file in both the pages.

in the first page, set the variables after your validation.

in the second page retrieve the values from the variable.

2. use Query string(this is better and easy).

query strings are the name value pairs which are passed in the url itself.

eg: _http://test.com/submitpage.html?key1=value1&key2=value2

here is a sample for accessing query strings using Javascripts.

Code:
var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsParm[key] = val;
}
}
}

Source for #2
Zangetsu
Feb 10, 2012 at 10:38 AM
I recommend using query strings
T
Jan 16, 2013 at 11:29 AM
Hello

I have recommend using query strings of the java in JS file is very important technique.
abhidev
abhidev #7
Jan 16, 2013 at 12:24 PM
you can use two kinds of approach.
1. use global JS variables, include the variables in a JS file and refer those files in both the pages.
Ex: create test.js

Code:
// filename.js
var test1;
var test2;

then refer this JS file in both the pages.

in the first page, set the variables after your validation.

in the second page retrieve the values from the variable.
How are u gonna retain the global variables on different pages when the pages are itself getting refreshed :/ ...unless he is using ajax.
A
Jan 17, 2013 at 6:57 PM
you can use query string or you can use ajax