CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   pass data using post between html pages (http://www.codingforums.com/showthread.php?t=285550)

kaanta 01-10-2013 05:17 AM

pass data using post between html pages
 
Hi,
I want to pass values between 2 html pages using POST method. I have lot of data to be passed to 2nd page and cannot use GET. My issue is I dont know how to pass values to second html page and how do i display username on page 2.
pls help.

page1.html
[CODE]
<html>
<head>
<title>Form</title>
</head>
<body>
<h4>Enter your name</h4>
<form name="form1" method="post" action="page2.html">
<input type="text" name="username">
<input type="submit" onclick="submitForm()">
</form>
<script type="text/javascript">
function submitForm()
{
form1.submit();
}
</script>
</body>
</html>

page2.html

<html>
<head>
</head>
<body>
....... dont know how to display username entered on page1.html here...
</body>
</html>

[CODE]

sbhmf 01-10-2013 07:09 AM

Use Request.Form("controlName")...

based on your first page, you may imbed the submitted data into the second page's controls following the syntax above:

<html>
<head><title>page 2</title>
<script type="text/javascript">
function fnLoad(){
/*This will append the submitted name to the content of this page:*/
document.getElementById('me').innerHTML += Request.Form('username') + '.';
}
</script>
</head>
<body onload="fnLoad()">
<p id="me">Yo, I'm </p>
</body>
</html>

felgall 01-10-2013 07:32 AM

How you get the posted values to display in the second page depends on which server side language you are using to construct the page. JavaScript can write POST data but cannot read it.

kaanta 01-10-2013 01:39 PM

I don't have any server side script. I don't know if Request object is available in JavaScript. Will it mean that I cannot post data between htmls and js only?

felgall 01-10-2013 10:16 PM

Request.form is the ASP way of reading the posted data (one of the many server side languages that can process data that has been POSTed).

JavaScript can only read data from a form on the prior page when the form used GET to pass the information in the querystring on the end of the address.

The alternative would be to have the JavaScript that is called when the form is submitted save the information in a cookie and then call the following page without actually submitting the form. The following page could then read the information from the cookie using JavaScript.

Without a server side language you would still have no way to pass the information from one page to the other for anyone who doesn't have JavaScript enabled in their browser.

kaanta 01-11-2013 04:51 PM

Thank u felgall for helping.
One more quesrion..If I introduce aspx page like default.aspx, can u suggest how do I load page2.html after reading post values in aspx code and making these values available on page 2

sbhmf 01-12-2013 10:46 AM

I don't think it's a good idea to start learning server-side coding prior to mastering a good working knowledge of client-side coding. You don't NEED a server to accomplish your objective.

Another way to pass information form one page to another is by appending it to the querystring.

The recipient page simply needs to parse the querystring to get the values. Something like...

var qs = location.href.split('?')[1];
vat tokens = qs.split('&');

now each token in the tokens array contains a property/value pair, formatted as propertyName=Value.

kaanta 01-12-2013 01:59 PM

I cannot use query string/get because there are lots of values to be sent to page 2. Even if it is within limit now, if I get to enhance app for next work then there might be more in future.

rnd me 01-13-2013 12:39 AM

POST is something that you do to a server, so it doesn't make sense that a client side page would be able to read it.

if you need more room than GET or cookies (both are about the same limit), use localStorage or window.name to persist data across pages.


All times are GMT +1. The time now is 06:06 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.