omer malka omer malka - 1 year ago 82
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 ]


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>


Answer Source

Your syntax is wrong . is not a valid parameter identifier

function login(user, pass) {
    if(localStorage.getItem('username').indexOf(user) >= 0  ) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download