iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 17, 2008
Learn HTML forms
About
 
May 16, 2008
Who Are Your Top Friends on Facebook?
About
 
May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /JavaScript

Retrieving variables passed from earlier pages 

  Views:    4840
  Votes:    3
by Sathya Anandakrishnan 3/05/04 Rating: 

Synopsis:

Synopsis: Retrieve variables passed from earlier pages through client side scripts.
Pages: 
The Article

You need not necessarily visit the server side scripts (such as VBscript) to retrieve the variables passed across from the prior page. The same result can be produced using just Javascripts.
Variables passed from the last page can be retrieved in your current page in a Javascript function as follows:

function fn_RetrieveVariables()
{
// Identify browser type
var strNav, strIE, strBrowser; 
strNav = (navigator.appName == "Netscape" &&
        parseInt(navigator.appVersion) >= 3);

strIE = (navigator.appName.indexOf("Microsoft") >= 0 &&
parseInt(navigator.appVersion) >= 4) ;

strBrowser = strNav || strIE;

var results = new Array();

if (strBrowser)
{
// strip away leading question mark
var input = unescape(location.search.substring(1));
if (input)
{
// Divide long string into array of name/value pairs.
var srchArray = input.split("&");
var tempArray = new Array();
for (i = 0; i < srchArray.length; i++)

/* Divide each name-value pair into a two-entry array.*/
tempArray = srchArray[i].split("=");
results[tempArray[0]] = tempArray[1];
   }
        }
    }
    return results;
}

 

Variables Value1 and Value2 passed from prior page as:


mytestpage.html?Value1=1&Value2=2

can be retrieved in results of the above function.

For users averse to passing query strings, the same works effectively with hidden variables too.

Pages: 



 
  Sponsors