简体   繁体   中英

How to display user input from one html page to another html page (javascript)

I have one HTML page (test.html)

<!DOCTYPE html>
<html lang="en"> 
    <head>
        <title>test</title>
    </head>
    <body>
        <input type="text" id="input-text" placeholder="Enter Text here"> <!--input text-->
        <input type="button" id="btn" onclick="addText()" > <!--call function-->
        <button ><a href="test2.html">Next Page</a></button> <!--get to new html page-->
    </body>
    <script src="app.js"></script>
</html>

and another HTML (test2.html)

<!DOCTYPE html>
<html lang="en"> 
    <head>
        <title>test2</title>
    </head>
    <body>
        <h1 id="header">Display input here</h1>
    </body>
    <script src="app.js"></script>
</html>

I want to go from one page to the other. The first page has an input, and the second page should display the input made by the user at the first page. This is the JavaScript:

function addText()
{
    document.getElementById('header').innerHTML 
    =document.getElementById('input-text').value;
}

How to display my user input from test page to test2 page?

Create a JSON object to store the data in localStorage. Then pull that data from the object when loading the next page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM