0
Javascript
function user(){
input = document.getElementById("user").value;
label = document.getElementById("tuser");
if(label.style.display == "block"){
if(input.length >= 1){
label.innerHTML = "Usuário deve conter mais 5 caracteres.";
if(input.length >= 5){
label.style = "display:none";
}
}
}
}
function pass(){
input = document.getElementById("pass").value;
label = document.getElementById("tpass");
if(label.style.display == "block"){
if(input.length >= 1){
label.style = "display:none";
}
}
}
Both are not running, so it returns an error in the Chrome Console
(index):225 Uncaught TypeError: pass is not a function
at HTMLInputElement.onkeypress ((index):225)
HTML (calls function)
<input type="text" name="usuario" id="user" onkeypress="user()" autofocus maxlength="12" value="" class="form-control" placeholder="Seu Usuário">
<input type="password" name="senha" id="pass" onkeypress="pass()" maxlength="16" class="form-control" placeholder="Sua Senha">
Function will make change in
<font color="#ff0000" id="tuser" class="animation-slideUp inserted" style="display:none;">Insira seu usuário.</font>
<font color="#ff0000" id="tpass" class="animation-slideUp inserted" style="display:none;">Insira sua senha.</font>
I found it very strange that this happened, because the codes are "correct" (I think). I ran them on the console and there was no error.
Were these JS functions defined in the HTML file itself or in a separate JS file? If it is separate, how did you include the JS file in the HTML file?
– Woss
Defined in HTML file itself.
– Progrando
Can you enter the full code? In fact, avoid using the element
font
. It has been obsolete since HTML 4.– Woss
Progressing, apart from the code, tell us what you want with this code, maybe we can help you with logic, because I realized there’s enough unnecessary stuff. ;)
– Leonardo Bonetti
Your problem is some error on a line before these functions. So the script did not load them into memory and in practice they became nonexistent. So it’s good to post the full code to analyze.
– Sam
After sending the form the javascript checks if the fields have been filled in, if the field is not filled in an error message will appear below the input (in this case the label). So if you type in the input the message will disappear, and in the user after the first digit will appear an error that needs to be more than 5 characters, then type the 5 and the error disappears.
– Progrando
Function validate(){ var Valid = true; if (Document.formlog.usuario.value == ""){ Document.getElementById('tuser'). style = "display:block;"; Valid = false; } if(Document.formlog.password.value == ""){ Document.getElementById('tpass'). style = "display:block;"; Valid = false; } if(Valid == true){ Loader(); } Return Valid; }
– Progrando