I started yesterday to study JavaScript
and I am having difficulty in search validation.
I'm following the steps in a book I'm using for the proposed project.
I needed to send the search form, that is, when I confirmed the search with the unfilled field the function trigger a Alert
with a message and did not proceed with the search. However, Alert
is being triggered when refreshing the page. Here's the code photo.
function validaBusca() {
if(document.querySelector('#q').value == ''){
alert('Campo de busca vazio, por favor preencha o campo!');
return false;
}
}
//Fazendo a associação da função com o evento
document.querySelector('#form-busca').onsubmit = validaBusca();
The Value
and onsubmit
are not in the autocomplete of IDE
( WebStorm
). Is this normal?