Hello everyone, i am creating a website where i need to store some data from the signup form in some arrays(i need them for the login form, to check if the specific person has already an account). I need to store only the data from a few people as the website is just for simulation. So i tried local storage but the following message shows up every time: JSON.parse: unexpected character at line 1 column 1 of the JSON data(running in firefox browser) and Uncaught SyntaxError: Unexpected token u(running in chrome browser). Thanks in advance :) My code is:
var people= [];
var passwords= [];
function loginbutton(){ //onclick function in login form
var usnm = document.getElementById("username").value;
var pswd = document.getElementById("password").value;
var op=localStorage.getItem('peoplenames');
var op1=JSON.parse(op);
for(var i = 0; i < op1.length; i++) {
if(usnm===op1[i]){
alert("user found");}
else{
alert("no user with that username");}
}
}
function submitSignUp(){ //onclick function in sign up form
var user = signupform.elements["username"].value;
var pass = signupform.elements["password"].value;
people[people.length]=user;
passwords[passwords.length]=pass;
localStorage.setItem( 'peoplenames', JSON.stringify(people[people.length]));
localStorage.setItem( 'passwords', JSON.stringify(passwords[passwords.length]));
}