0
I started studying yesterday JavaScript
and I’m having a hard time with the search validation.
I am following the steps of a book that I am using for the proposed project.
Needed to send the search form, IE, when confirming the search with the field unfilled the function trigger a Alert
with a message and did not proceed with the search. However, the Alert
is being fired when refreshing the page. Follow 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
). This is normal?
Laércio, as informed by the author of the question. He started learning Javascript yesterday. I believe that a better explanation of the answer would be of great help to him. It may be that he does not know what it is
addEventListener
or even how to call the method directly from HTML.– Bsalvo
@Bsalvo, understood, I’ll explain.
– Laércio Lopes