![]() |
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] |
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> |
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.
|
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?
|
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. |
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 |
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. |
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.
|
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.