0

I have two HTML pages: index.html and confirmation.html.

In index.html, there is a form:

<form>
    <label id="labelforename">Forename</label>
    <input type="text" name="textforename">

    <label id="labelsurname">Surname</label>
    <input type="text" name="textsurname">

    <input type="button" onclick="myFunction()"></input>

<script>
    function myfunction(){
        setTimeout(function() {window.location = "confirmation.html" });
    }
</script>
</form>

In confirmation.html there is a page whose purpose is confirming the entered first name and surname.

<body>
<div id="write"><p>Your name is: </p></div>

<script>
    function show() {
        document.getElementById("write").innerHTML = textforename;
        document.getElementById("write").innerHTML = textsurname;
    }
</script>

</body>

How can I pass forename and surname through the 2 pages and display it on the confirmation page?

Is it done by storing the forename and surname in a cookie on index.html and then getting it again when on the confirmation page and displaying it?

This needs to be done in jQuery or plain JavaScript.

INElutTabile
  • 866
  • 2
  • 20
  • 38
  • The only way to do this is `localStorage`. JavaScript does not persist through browser states without some sort of database style storage. – Sterling Archer Dec 01 '15 at 15:47
  • @SterlingArcher is that Cookies? – salman2k15 Dec 01 '15 at 15:47
  • No, it's just [string storage in your browser](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) – Sterling Archer Dec 01 '15 at 15:48
  • 1
    You can use cookies too though. – Victor Levin Dec 01 '15 at 15:48
  • @SterlingArcher could you give me a short example? I'm looking through the link you sent me and im trying to understand it – salman2k15 Dec 01 '15 at 15:49
  • Also right now you replace the forename by the surname. You likely want `document.getElementById("write").innerHTML += textforename; document.getElementById("write").innerHTML += textsurname;` – mplungjan Dec 01 '15 at 15:50
  • @Zealander how do i use cookies? – salman2k15 Dec 01 '15 at 15:50
  • @salman2k15 the example supplied on the documentation is the exact same example I would use. setItem and getItem are your friend – Sterling Archer Dec 01 '15 at 15:50
  • @mplungjan I disagree with your Golden Hammer. This question isn't specifically about cookies, as localStorage is also a viable solution here. It's better to close as too broad, than a duplicate of a duplicate that doesn't touch all possible solutions. – Sterling Archer Dec 01 '15 at 15:52
  • Cookies: http://www.w3schools.com/js/js_cookies.asp Also why not pass firstname & lastname to confirmation.html and parse the URL parameters on the other end --- see here: http://stackoverflow.com/questions/5448545/how-to-retrieve-get-parameters-from-javascript – Victor Levin Dec 01 '15 at 15:53
  • @SterlingArcher It became a duplicate when the user asked "How do I use cookies" and it is fairly obvious the solution is cookies or localstorage. I quote: _Is it to do with storing the forename and surname in a cookie on index.html and then getting it again when on the confirmation page and displaying it._ – mplungjan Dec 01 '15 at 15:56
  • why not just post the form normally using get method and then on the confimation use your js to get the variables on the confimation page (http://stackoverflow.com/questions/10001726/access-get-variables-using-jquery-javascript) – Pete Dec 01 '15 at 15:56
  • I agree with @Sterling - there is no "cookies" at all in the question itself. Using cookies is just one way. Reopened. – Shadow The GPT Wizard Dec 01 '15 at 16:12

0 Answers0