0
I am creating a form and need to alert the user when a field is not filled. I am trying to use the if to make this comparison, I have tried to compare with null and it did not work. my code is like this:
function Cadastrar(){
var titulo = document.getElementById("titulo").value;
var editora = document.getElementById("editora").value;
var conteudoTabela = document.getElementById("livros_cadastrados");
var novaLinha = document.createElement("tr");
if(titulo == null || editora == null){
alert("Dados incompletos");
}else{
novaLinha.innerHTML = "<td>" + titulo + "</td><td>" + editora + "</td><td><a href='' class='botaoExcluir'>Excluir</a>";
conteudoTabela.appendChild(novaLinha);
alert("Novo livro cadastrado:" + "\n" + titulo);
}
}
I’m quite a beginner, so if possible, I’d like a very detailed explanation. Thank you very much!
Where are you calling that function
Cadastrar
?– Sergio