I'm working on a form which if the person does not fill in the fields, the <input>
is left with a red border, and below is the name "Required field".
It's working fine, but I need it when the person completes the field it returns to its normal state, without red border and without the name that is inserted "Required field". Well it appears, but do not disappear after it's filled!
Before After-Wrong After-Howtostay The
<form>
isasfollows:<formclass="form-horizontal" id="formulario" name="formulario" method="get"
action="http://localhost/br/p/124678139/" onsubmit="return valida_form(this)"></form>
My Javascript code:
function valida_form (){
if(document.getElementById("nome").value.length < 3){
document.getElementById("nome").focus();
document.getElementById("nome").style.border = "1px solid #ef3c59";
document.getElementById("textinho").innerHTML='<p class="help-block ng-binding" style="color:#ef3c59;">Campo obrigatório</p>';
return false
}
}
I also need to make it work in the email field, in which I use the following code:
function valida_form (){
var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if(!filter.test(document.getElementById("emaile").value)){
document.getElementById("emaile").focus();
document.getElementById("emaile").style.border = "1px solid #ef3c59";
document.getElementById("textinho2").innerHTML='<p class="help-block ng-binding" style="color:#ef3c59;">E-mail inválido</p>';
return false
}
}