omer malka omer malka - 2 years ago 65
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 ]


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

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


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

<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>


ty for all the help !!

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download