omer malka omer malka - 7 months ago 11
Javascript Question

How to check if i have 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 for be clear i make an array that everytime 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>


ty for all the help !!

Answer

It seems like you're not passing user into your function unless it is globally declared somewhere else in your code. You are passing in user.value which is not a valid param name, you will need to pass just user and pass in so an example of how to invoke it would be.

login('fooUser','barPassword');