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 

thanks 

Alok 
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:

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

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

<html>
<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>");
</script>
</html>

Hope the above helps.
Refer  http://www.javascriptkit.com/javatutors/send1.shtml  which will be very useful.

Thanks & Regards,
Rajasekhar.R

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

var name = document.getElementById("<%= TextBox1.ClientID %>").value;
window.open("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_;
      else
        return qs[1];
    }
 
    var id = getQuerystring('id');
 
 
    document.getElementById("<%= TextBox1.ClientID %>").value = id;
 
</script>