omer malka omer malka - 7 months ago 11
HTML Question

How to check if I have a specific value inside my localStorage?

I want to check if the name value I put in the input exists inside my local Storage by the key 'username'. [ just to be clear I make an array that every time I make a new register it adding the new username to the array and to the localStorage I insert the array ]

javascript:

function login(user.value,pass.value){

if(localStorage.getItem('username').indexOf(user) >= 0 )
alert('hey')
}


html:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Login Page </title>
<link rel="stylesheet" href="css/loginpage.css" />
<script type="text/javascript" src="js/loginpage.js"></script>
</head>
<body>

<div>
<input id="user" type="text" placeholder="Enter the Name"/>
<input id="pass" type="password" placeholder="Enter the Color"/>
<button onclick="login(user,pass)">Login</button>
<a href='file:///C:/Users/DELL/Desktop/HackerU/Web/site/site.html'> <button>New Register</button></a>
</div>

</body>

Answer

Your syntax is wrong . is not a valid parameter identifier

function login(user, pass) {
    if(localStorage.getItem('username').indexOf(user) >= 0  ) {
        alert('hey');
    }
}