1
I am working on a form which if the person does not fill in the fields, the <input>
gets a red border, and at the bottom appears the name "Required field".
Everything is working fine, but I need that when the person fills the field he returns to his normal state, without red border and without the name that is inserted "Mandatory field". 'Cause he shows up, but he doesn’t disappear!
Before
After - Wrong
Then - How it should look
The
<form>
is as follows:
<form class="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
}
}
What recent changes? You changed the question?
– Maniero
Yes, I had not put the email script, and the user of the previous reply is not a very frequent user.
– Alexandre Lopes
The problem is that you cannot change the question and invalidate the answers given. The question asked and answered must remain the same. The amendment creates a problem.
– Maniero
But I warned the other friend, but he disappeared days ago. Then he went unanswered.
– Alexandre Lopes
He gave the answer, closed it. You want something different, you have to open a new question. Editing to change the content of the question and asking people to update their answers is not a valid option.
– Maniero
I’ll stop right there.
– Alexandre Lopes
You actually have to ask the full question at once. If it was a new user, I would understand, but I think I can see that here is a site of objective questions and objective answers, and not "progressive consulting" right? : P
– Bacco