JavaScript - HOW we send value of page to another in java script

Asked By ALOK RANJAN on 02-Jul-12 03:30 AM
how we send a value from one page to another in javascript??  and how we retrieve on next page  please solve ASAP 


RAJASEKHAR RAJENDRAN replied to ALOK RANJAN on 02-Jul-12 04:09 AM
Hi Alok,

Find the Below Sample that can give you idea to achieve your desired results.

Lets consider the below as the First Page:

<form type=get action="page1.html">
<td>First Name:</td>
<td><input type=text name=Fname size=10></td>
<td>Last Name:</td>
<td><input type=text name=Lname size=10></td>
<td colspan=2><input type=submit value="Submit">

Lets Get the above value passed in the Second Page using JAVASCRIPT:

<script LANGUAGE="JavaScript">
function getParams(){
var index = document.URL.indexOf('?');
var params = new Array();
if (index!= -1) {
var pair = document.URL.substring(index+1, document.URL.length).split('&');
for (var i=0; i<pair.length; i++){
nameVal = pair[i].split('=');
params[nameVal[0]] = nameVal[1];
return params;
params = getParams();
Fname = unescape(params["Fname"]);
Lname = unescape(params["Lname"]);

document.write("firstname = " + Fname+ "<br>");
document.write("lastname = " + Lname+ "<br>");

Hope the above helps.
Refer  which will be very useful.

Thanks & Regards,

dipa ahuja replied to ALOK RANJAN on 02-Jul-12 04:11 AM
Parent form :

var name = document.getElementById("<%= TextBox1.ClientID %>").value;"page2.aspx?id=" + name);
Child Form:
<script type="text/ecmascript">
    function getQuerystring(key, default_) {
      if (default_ == null) default_ = "";
      key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
      var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
      var qs = regex.exec(window.location.href);
      if (qs == null)
        return default_;
        return qs[1];
    var id = getQuerystring('id');
    document.getElementById("<%= TextBox1.ClientID %>").value = id;