Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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]

  • #2
    New Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    98
    Thanks
    6
    Thanked 7 Times in 7 Posts
    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>

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    New Coder
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New Coder
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #7
    New Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    98
    Thanks
    6
    Thanked 7 Times in 7 Posts
    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.

  • #8
    New Coder
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    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.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •