I've been trying to make a simple form validation js project, and my first logic statement itself had an error. When I tried to log out the value of my input it says that it is undefined:
<!--skipped css-->
<html>
<head>
<title>
Form validation
</title>
</head>
<body>
<div class="transparent">
<div class="form">
<h1 class="login"> Login </h1>
<form>
<label for="name" class="LName">Name</label>
<input class="name" id="name" name="name" placeholder="Enter your username"><br>
<label for="email" class="LEmail">E-mail</label>
<input class="email" id="email" name="email" placeholder="Enter your E-mail"> <br>
<label for="password" class="LPassword">Password</label>
<input type="password" class="password" id="password" name="password" placeholder="Enter your password"><br>
</form> <br>
<button class="btn"> Login </button>
<br> <br>
<span> OR </span><br> <hr>
<button class="gbtn"> <i class="fab fa-google"></i> Sign in with Google </button>
</div>
</div>
<script>
var name = document.getElementById('name');
var email = document.querySelector('.email');
var password = document.querySelector('.password');
var btn = document.getElementsByClassName('btn')[0];
btn.onclick = empty;
function empty() {
name = document.getElementById('name');
console.log(name.value);
if(name.value == "") {
name.classList.add('errInp');
}
}
</script>
</body>
</html>
I believe I've assigned all the vars, and I've tried changing it to innerText too, only to get another undefined. Can someone help me out?