2021年2月3日星期三

Set input value of form to a value from previous form

I am trying to make a login where the user submits their username in a form, then that username is carried over to another page and saved as a value in the name input field. The saved username on the second page is showing up as [object HTMLInputElement], when it should be the username they entered on the first page.

index.html (first page)

<!DOCTYPE html>  <html lang="en" dir="ltr">    <head>    <meta charset="utf-8">    <title>Login Form</title>      <link rel="stylesheet" href="style.css">    </head>    <body>        <form id ="form" action="results.html" method="get">      <div class="login-box">        <div id="error"></div>        <h1>Login</h1>          <div class="textbox">          <i class="fas fa-user"></i>          <input id="name" type="text" placeholder="Username" name="name" required>        </div>        <button type="submit" id ="submit">Sign in</button>        <button type="reset" name="reset" id = "reset">Reset</button>        </div>      </form>    </body>  </html>  

results.html (second page)

<!DOCTYPE html>  <html lang="en">    <head>      <meta charset="utf-8">      <meta name="viewport" content="width=device-width,initial-scale=1.0">      <meta http-equiv="X-UA-Compatible" content="ie=edge">      <title>Results</title>    </head>    <body>  <div id = "results"></div>    <a href="/">Back to Form</a>      <form id ="form" action="results.html" method="get">    <div class="login-box">      <div id="error"></div>      <h1>Login</h1>        <div class="textbox">        <i class="fas fa-user"></i>        <input id="name" type="text" name="name">          <script type="text/javascript">          document.getElementById('name').setAttribute('value', document.getElementById('name'))        </script>      </div>        <div class="textbox">        <i class="fas fa-user"></i>        <input id = "password" type="password" placeholder="Password" name="password" value="">      </div>          <button type="submit" id ="submit">Sign in</button>      <button type="reset" name="reset" id = "reset">Reset</button>        </div>    </body>  </html>  

Edit for clarity: I'm trying to recreate the login funcionality like this website's Online Login

https://stackoverflow.com/questions/66038407/set-input-value-of-form-to-a-value-from-previous-form February 04, 2021 at 10:10AM

没有评论:

发表评论