9
I’d like you to fill in a piece of data input this was being validated, that is, as it was filling a field 'nif' that alerted me an "invalid nif" message until it was correct and did not need to use methods such as the onBlur.
Does anyone know a way to do it?
My code:
function teste(){
var input = document.getElementById("input").value;
if(input == 5){
document.getElementById("5").innerHTML = "sucesso";
}else{
document.getElementById("5").innerHTML = "insucesso";
}
}
<input type="text" id="input" onchange='teste()'>
<h2 id="5"> </h2>
Do you have any code developed?
– João Pedro Schmitz
https://www.w3schools.com/jsref/event_onkeypress.asp
– Marconi
W3schools is a problem, do not use their link. keypress on MDN will see that the event is discontinued and the advised is to use the event
keydownorbeforeinput. Not to mention that at MDN teaches to useaddEventListener(which is the best way) instead of event in attributes.– fernandosavio