1

Below is a quick function I wrote to check that the input supplied is equal to some pre-defined value. If it is, then it should display "Login Successful".

function getUsername(){
  var username = document.getElementById("userID").nodeValue;
  var password = document.getElementById("password").nodeValue;
  if (username=="example@example.com" && password=="123"){
  alert('Login Successful');
  }   
}
<input class="input100" type="text" name="username" placeholder="Username" 
id="userID">

<input class="input100" type="password" name="pass" placeholder="Password" 
id="password">

<Button class="login100-form-btn" onclick="getUsername()">Login</Button>
Code Maniac
  • 35,187
  • 4
  • 31
  • 54
Silvernail
  • 11
  • 1

1 Answers1

1

You should use .value for obtaining values of input elements:

function getUsername() {
  var username = document.getElementById("userID").value;
  var password = document.getElementById("password").value;
  if (username == "example@example.com" && password == "123") {
    alert('Login Successful');
  }
}
<input class="input100" type="text" name="username" placeholder="Username" id="userID">

<input class="input100" type="password" name="pass" placeholder="Password" id="password">

<Button class="login100-form-btn" onclick="getUsername()">Login</Button>
Jack Bashford
  • 40,575
  • 10
  • 44
  • 74