javascript pass variable next page

mohityadavx

Youngling
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.
 

Abhinav1217

Right off the assembly line
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

The Mighty Unkel!!!
Staff member
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
 

abhidev

Human Spambot
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.
 
Top Bottom