dimanche 5 juillet 2020

Linking multiple .html files to one .js file

I want to create a simple login and sign up page. I have created them separately using atom, and they were saved inside the same folder inside my computer. I added a css file and was able to link it to both fine.

Now comes the problem.

Note: This is just a fun little project which is why I only used localStorage.

I created a .js file inside my website folder.

function create(){
  window.location.href = "file:///C:/Users/User/OneDrive/Desktop/Social_Share/ssprofile.html";
    var un = document.getElementById("username").value;
    var pw = document.getElementById("password").value;
    localStorage.setItem(username, un);
    localStorage.setItem(password, pw);
}
//LOGIN PAGE
function login(){
  if(document.getElementById("usernamel") = localStorage.getItem(username)){
    if(document.getElementById("passwordl") = localStorage.getItem(password)){
      window.location.href = "file:///C:/Users/User/OneDrive/Desktop/Social_Share/ssprofile.html";
    }else{
      document.getElementById("errormsg").innerHTML = "Incorrect Password or username";
    }
  }else{
    document.getElementById("errormsg").innerHTML = "Sorry, this account does not exist";
  }
}

And made it to add values to the localStorage when create account button is pressed.

<script src="ssjavascript.js"></script>

This is the exact same code I used for both the html files to connect to the js files, and yet, only one works. No matter what, only one of the html files can connect to the js file. I've copied and pasted multiple times. I've tried different tags. I've tried everything I can think of and this is where I beg the internet myself for answers.

Please help a noob




Aucun commentaire:

Enregistrer un commentaire