-3

I am trying to make a Sign Up and Log In html. If user inputs data on SignUp.html, it will save as localStorage and if the data inputted on LogIn.html is not equal to the data inputteed in SignUp.html, it will not confirm. But somehow there is something wrong with the function. Can someone please help me? I am still new to js

Here is SignUp.html

<!DOCTYPE html>
 <html>
  <head>
   <script src = "JS.js"></script>
  </head>
  <body>
   <form>
    <input id="usernameS"></input>
    <button onclick="confirmInput()" type="button">SignUp</button>
   </form>
  </body>
 </html>

and LogIn.html

<!DOCTYPE html>
 <html>
  <head>
   <script src = "JS.js"></script>
  </head>
  <body>
   <form>
    <input id="usernameL"></input>
    <button onclick="LogInput()" type="button">LogIn</button>
   </form>
  </body>
 </html>

Here is the js

var x = "document.getElementById('usernameS')";
    localStorage.setItem("usernameS", x);
    var y = "document.getElementById('usernameL')";
    localStorage.setItem("usernameL", y);

    function confirmInput() {
    alert("Welcome " + usernameS.value + ". You are now registered.");
    window.location.replace('LogIn.html'); }

    function LogInput(x,y) {
    if (x==y)
    {unsernameS = document.forms[0].usernameL.value;
    alert("Welcome " + usernameL.value + "! You just logged in.");}
        else if (x!=y)
        alert("Username not recognized");}
Jay
  • 1
  • You can use `storage` event to communicate between separate `window`s loaded at same origin [Can the mechanism that loads the worker in Shared Web Workers be modified?](http://stackoverflow.com/questions/38938039/can-the-mechanism-that-loads-the-worker-in-shared-web-workers-be-modified/), see also [JavaScript Session storage variable on another page](http://stackoverflow.com/questions/38034647/javascript-session-storage-variable-on-another-page) – guest271314 Feb 18 '17 at 04:17

1 Answers1

0

At least Fix typo in your code {unsernameS = document.forms[0].usernameL.value;

Janne
  • 1,665
  • 15
  • 22