I'm doing some testing to learn more about callback
in javascript and found the following difficulty:
function nome_existe(element) {
console.log(element.id);
}
window.onload = function() {
Array.from(document.getElementById("form_id")).forEach(function(element, index) {
element.addEventListener("blur", nome_existe(element));
});
};
<form id="form_id" method="POST" action="/cloud/criar-conta.php" autocomplete="off">
<input type="text" name="input_nome" id="input_nome" placeholder="Insira um nome" value="" /><br/>
<input type="text" name="input_email" id="input_email" placeholder="" value="Insira um email" /><br/>
<input type="text" name="input_email_c" id="input_email_c" placeholder="" value="Confirme seu email" /><br/>
<input type="text" name="input_tel" id="input_tel" placeholder="" value="(DDD) - _____ - ____" /><br/>
<input type="password" name="input_senha" id="input_senha" placeholder="Digite uma senha" value="" /><br/>
<input type="password" name="input_senha_c" id="input_senha_c" placeholder="Confirme sua senha" value="" /><br/>
<input type="checkbox" name="input_check" id="input_check" onblur="valida_check()" />
<p id="termo_cad">Concordo com os Termos de Serviçes e Política de Privacidade</p>
<input type="submit" name="sub_btn" id="sub_btn" value="Enviar" />
</form>
form
into a array
and theoretically (in my mind) should assign a listner
to the field that received the blur
event and then log the id
of the element in the% console.
The difficulty is: Why is running the onload
event on the console the ids
of all elements, even without the blur
event occurring?