Home Tutorial Javascript Populate values from html to another html

 
 

Populate values from html to another html
Posted on: December 8, 2012 at 12:00 AM
Advertisement
In this tutorial, you will learn how to send values from one html page to another.

Populate values from html to another html

In this tutorial, you will learn how to send values from one html page to another. Here, we have create a html form that contains three fields: firstname, lastname and age. When the user enters all the fields and click submit button, all the values will get displayed on another html page.

page1.html:

<html>
<form type=get action="page2.html">
<table>
<tr>
<td>First Name:</td>
<td><input type=text name=firstname size=10></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type=text name=lastname size=10></td>
</tr>
<tr>
<td>Age:</td>
<td><input type=text name=age size=10></td>
</tr>
<tr>
<td colspan=2><input type=submit value="Submit">
</td>
</tr>
</table>
</form>
</html>

page2.html:

<html>
<script LANGUAGE="JavaScript">
function getParams(){
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++){
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
document.write("firstname = " + firstname + "<br>");
document.write("lastname = " + lastname + "<br>");
document.write("age = " + age + "<br>");
</script>
</html>

Advertisement

Related Tags for Populate values from html to another html:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 8, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com