-2
Well, I’m trying to block a button when the inputs are not filled in the form but I can’t, I’ve seen several examples of code that worked but even when I try to copy, they make the same mistake. Uncaught Typeerror: Cannot read Property 'addeventlistener' of null
html
<fieldset id="fie">
<legend>LOGIN</legend>
<div class='campo'>
<label for="login">Nome:</label>
<input type="text" name="login" id="login" required>
</div>
<div class="campo">
<label for="senha">Senha:</label>
<input type="password" name="senha" id="senha" required>
</div>
<button type="submit" class="btn" >Login</button>
</fieldset>
Javascript
let btn = document.querySelector('btn');
let login = document.querySelector('login');
let senha = document.querySelector('senha');
login.addEventListener('keyup', verificar(login));
senha.addEventListener('keyup', verificar(senha));
function verificar(verificado){
if(verificado.value.lenght < 3 ){
btn.disabled = true;
}else{
btn.disabled = false;
}
}
The querySelector method accepts a micro-language similar to jQuery. I believe you want to select elements by class, so you have to put a dot in front of each name e.g. querySelector('.btn'). If you were to select by id you would have to put the # in front.
– epx