Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

I have created a register using javascript from which data is getting stored in the local storage, but I want to retrieve data from local storage for login purpose, following is my controller.js-

//Storing data from local storage into an array of objects

 var usersdata = JSON.parse( localStorage.getItem('key_users' ) );

function validatelogin()

{

    usersdata = JSON.parse( localStorage.getItem('key_users' ) );

    var usernameinput   = document.getElementById("username");

    var passwordinput   = document.getElementById("password");

    for(var p in userdata)

    {

      console.log(p+':'+userdata[p].username+'|'+userdata[p].email);

      if(usernameinput==userdata[p].username && passwordinput==userdata[p].password)

      {

         alert("Logged in successfully");

      }

    }

}

While I try to log in, it gives an error called ‘userdata’ is not defined. Please help with what’s wrong with the code?

1 Answer

0 votes
by (13.1k points)

Inside the for loop change userdata to usersdata

Want to be a full-stack development? Check out the full-stack developer course from Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Mar 2, 2021 in Web Technology by dhanush (13.1k points)
0 votes
1 answer

Browse Categories

...