0

How to stop looping once the uninput and pwinput matches with the array from LocalStorage?

function login() {
  existinglist = JSON.parse(localStorage["existinglist"]);
  var uninput = document.getElementById('UserName').value;
  var pwinput = document.getElementById('PassWord').value;
  for (var i = 0; i < existinglist.length; i++) {
    if (uninput == existinglist[i]['UserName'] && pwinput == existinglist[i]['Password']) {
      credential
      alert('You have login successfully!');
      break;
    } else {
      alert('Invalid login!');
    }
  }
}
<form action="             " class="loginform" onsubmit=' return login()'>
  <label>Username: </label>
  <input type="text" id='UserName' name="UserName" autocomplete='off' required>
  <label>Password: </label>
  <input type="password" id='PassWord' name="PassWord" autocomplete='off' required>

  <button type="submit">Log in</button>


</form>
devserkan
  • 16,870
  • 4
  • 31
  • 47

1 Answers1

0

Your second page for creating a user account does't exist. Your code will work, provided it is in a function and you remove those tags